我喜欢一般的“测试步骤”构想。我将其称为“增量”测试,在功能测试方案恕我直言中最有意义。
这是一个不依赖pytest内部细节的实现(官方钩子扩展除外)。复制到您的
conftest.py:
import pytestdef pytest_runtest_makereport(item, call): if "incremental" in item.keywords: if call.excinfo is not None: parent = item.parent parent._previousfailed = itemdef 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.incrementalclass 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.dev17plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov, timeoutcollected 3 itemstest_step.py .Fx=================================== FAILURES ===================================______________________ TestUserHandling.test_modification ______________________self = <test_step.TestUserHandling instance at 0x1e0d9e0> def test_modification(self):> assert 0E assert 0test_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插件需要发展一种方法来定义要整体出售给一个测试从属的组/类,而不是通常将类的测试功能发送给不同从属的当前模式。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)