假设我有这些测试功能:
def test_function_one():
assert # etc...
def test_function_two():
# should only run if test_function_one passes
assert # etc.
Run Code Online (Sandbox Code Playgroud)
如果test_function_one通过,我怎样才能确保test_function_two只运行(我希望它可能)?
编辑: 我需要这个,因为测试二使用测试验证的属性.
您可以将pytest插件称为pytest-dependency。
代码如下所示:
import pytest
import pytest_dependency
@pytest.mark.dependency() #First test have to have mark too
def test_function_one():
assert 0, "Deliberate fail"
@pytest.mark.dependency(depends=["test_function_one"])
def test_function_two():
pass #but will be skipped because first function failed
Run Code Online (Sandbox Code Playgroud)
Mar*_*hio -1
我想这就是你想要的:
def test_function():
assert # etc...
assert # etc...
Run Code Online (Sandbox Code Playgroud)
这满足您的要求,即仅当第一个“测试”(断言)通过时才运行第二个“测试”(断言)。
| 归档时间: |
|
| 查看次数: |
2111 次 |
| 最近记录: |