Din*_*ini 3 python pytest python-2.7
@pytest.mark.incremental
class Test_aws():
def test_case1(self):
----- some code here ----
result = someMethodTogetResult
assert result[0] == True
orderID = result[1]
def test_case2(self):
result = someMethodTogetResult # can be only perform once test case 1 run successfully.
assert result == True
def test_deleteOrder_R53HostZonePrivate(self):
result = someMethodTogetResult
assert result[0] == True
Run Code Online (Sandbox Code Playgroud)
当前行为是:如果测试1通过,则测试2运行,如果测试2通过,则测试3运行。
我需要的是:如果test_case 1通过则应该运行test_case 3。test_case 2不应更改任何行为。有什么想法吗?
我猜您正在寻找pytest-dependency允许在测试之间设置条件运行依赖项的条件。例:
import random
import pytest
class TestAWS:
@pytest.mark.dependency
def test_instance_start(self):
assert random.choice((True, False))
@pytest.mark.dependency(depends=['TestAWS::test_instance_start'])
def test_instance_stop(self):
assert random.choice((True, False))
@pytest.mark.dependency(depends=['TestAWS::test_instance_start'])
def test_instance_delete(self):
assert random.choice((True, False))
Run Code Online (Sandbox Code Playgroud)
test_instance_stop并且test_instance_delete仅在test_instance_start成功时运行,否则跳过。但是,由于test_instance_delete不依赖test_instance_stop,所以无论后者测试的结果如何,前者都将执行。多次运行示例测试类,以验证所需的行为。
| 归档时间: |
|
| 查看次数: |
539 次 |
| 最近记录: |