本文介绍了如果一项测试失败,pytest 跳过所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果特定测试失败,跳过所有剩余测试的最佳方法是什么,这里 test_002_wips_online.py 失败,然后进一步运行没有意义:

What is best way to skip every remaining test if a specific test fails, here test_002_wips_online.py failed, and then there is no point in running further:

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%]

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

I like to skip all remaining tests and write test report.Should I write to a status file and write a function that checks it?

@pytest.mark.skipif(setup_failed(), reason="需求失败")

pytest-skipif-reference

推荐答案

你真的应该看看 pytest-dependency 插件:https://pytest-dependency.readthedocs.io/en/latest/usage.html

You should really look at pytest-dependency plugin: 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

in this example test_d won't be executed if test_b fails

这篇关于如果一项测试失败,pytest 跳过所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 10:28