栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如果一个测试失败,如何跳过该类中的其余测试?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如果一个测试失败,如何跳过该类中的其余测试?

我喜欢一般的“测试步骤”构想。我将其称为“增量”测试,在功能测试方案恕我直言中最有意义。

这是一个不依赖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插件需要发展一种方法来定义要整体出售给一个测试从属的组/类,而不是通常将类的测试功能发送给不同从属的当前模式。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/637741.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号