私は一般的な「テストステップ」のアイデアが好きです。私はそれを「インクリメンタル」テストと呼んでおり、機能テストのシナリオで最も理にかなっています。
これは、pytestの内部詳細に依存しない実装です(公式のフック拡張機能を除く)。conftest.py
これをあなたの:にコピーしてください
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
次に実行すると、次のようになります(-rxを使用してxfailの理由を報告します):
(1)hpk@t2:~/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つのテストスレーブに卸売りで送信されるグループ/クラスを定義する方法を開発する必要があります。