我有一个pytest测试文件的目录,有一个需要测试的限定符测试,如果它失败了,那么停止执行任何进一步的测试,但是如果它通过了,那么执行所有测试,无论是否通过。
我有一个具有以下结构的目录:
tests/
test_qualifier.py
test_one.py
test_two.py
...
现在,当我使用pytest test/ -x
运行测试时,它运行所有的测试,假设它在第一次失败时停止。
我希望pytest
运行test_qualifier.py
,如果失败,则停止进一步执行,但如果通过,则无论任何测试是否失败,都不要停止
Tags:
您可以使用pytest插件。将其他测试标记为“取决于测试”限定符
从plugin page开始:
代码示例:
您可以通过使用pytest挂钩编写自己的pytest插件来实现这一点
一般来说,这不是一个很有意义的特性,所以我认为pytest不支持它
但是,您可能可以自己展开它:在
test_qualifier
中,创建一个autouse
fixture,如果其中一个测试失败,它checks the result of the test并调用类似pytest.exit
的东西。如果您想要正确的报告,也许可以检查一下exitfirst
的工作方式,我不知道直接调用pytest.exit
是否会生成正常的故障报告,因此这可能不太好除了
pytest.exit
之外,您还可以设置一个内部标志,a test running hook将使用该标志自动跳过所有后续测试您可能还想编写一个连接到pytest_collection_modifyitems的
conftest
插件,以确保您的资格测试始终首先运行,并且不会受到direntry迭代或字母顺序的影响相关问题 更多 >
编程相关推荐