如果特定测试失败,最好的方法是跳过每个剩余的测试,这里test_002_wips_online.py失败,然后继续运行毫无意义:

tests/test_001_springboot_monitor.py::TestClass::test_service_monitor[TEST12] PASSED [  2%]
tests/test_002_wips_online.py::TestClass::test01_online[TEST12] FAILED   [  4%]
tests/test_003_idpro_test_api.py::TestClass::test01_testapi_present[TEST12] PASSED [  6%]


我喜欢跳过所有剩余的测试并编写测试报告。
我应该写一个状态文件并编写一个检查它的函数吗?

@pytest.mark.skipif(setup_failed(), reason="requirements failed")

pytest-skipif-reference

最佳答案

您应该真正看一下pytest-dependency插件:https://pytest-dependency.readthedocs.io/en/latest/usage.html

import pytest

@pytest.mark.dependency()
def test_b():
    pass

@pytest.mark.dependency(depends=["test_b"])
def test_d():
    pass


在此示例中,如果test_b失败,则不会执行test_d

关于python - 如果一项测试失败,pytest跳过所有内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57462063/

10-14 19:01