私は一般的な "テストステップ"のアイデアが好きです。私はそれを「インクリメンタル」テストと呼んでおり、機能テストのシナリオIMHOで最も理にかなっています。ここで
は(公式フック拡張子を除く)pytestの内部詳細に依存しない実装です:
import pytest
def pytest_runtest_makereport(item, call):
if "incremental" in item.keywords:
if call.excinfo is not None:
parent = item.parent
parent._previousfailed = item
def pytest_runtest_setup(item):
previousfailed = getattr(item.parent, "_previousfailed", None)
if previousfailed is not None:
pytest.xfail("previous test failed (%s)" %previousfailed.name)
あなたは今、このような「test_step.py」をお持ちの場合:
import pytest
@pytest.mark.incremental
class TestUserHandling:
def test_login(self):
pass
def test_modification(self):
assert 0
def test_deletion(self):
pass
は、それが(XFAILの理由を報告するために-rx使用して)次のようになります実行している:
(1)[email protected]:~/p/pytest/doc/en/example/teststep$ py.test -rx
============================= test session starts ==============================
platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev17
plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov, timeout
collected 3 items
test_step.py .Fx
=================================== FAILURES ===================================
______________________ TestUserHandling.test_modification ______________________
self = <test_step.TestUserHandling instance at 0x1e0d9e0>
def test_modification(self):
> assert 0
E assert 0
test_step.py:8: AssertionError
=========================== short test summary info ============================
XFAIL test_step.py::TestUserHandling::()::test_deletion
reason: previous test failed (test_modification)
================ 1 failed, 1 passed, 1 xfailed in 0.02 seconds =================
私はここで "xfail"を使用しています。なぜなら、間違った環境や間違ったインタプリタのバージョンのスキップがあるからです。
編集:あなたの例も私の例も、分散テストでは直接動作しないことに注意してください。このため、pytest-xdistプラグインは、クラスのテスト機能を通常は異なるスレーブに送信する現在のモードではなく、1つのテストスレーブに全面的に送信されるグループ/クラスを定義する方法を拡張する必要があります。
--maxfailフラグを1に設定することはできませんか? 1つのテストが失敗した場合、それはpy.testの終了になります。 – Nacht
@Nacht他のテストケースが失敗したにもかかわらず、他のテストケースのテストを継続することですが、失敗したテストケースでテストステップを停止してください。 –