python - Pytest中如何控制增量测试用例
问题描述
@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
当前的行为是如果测试 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))
test_instance_stop
并且test_instance_delete
仅在test_instance_start
成功时运行,否则跳过。但是,由于test_instance_delete
不依赖于test_instance_stop
,所以无论后者的测试结果如何,前者都会执行。多次运行示例测试类以验证所需的行为。
推荐阅读
- javascript - 如何计算午夜 24 小时格式的时差
- java - 如何使用新的导航架构组件保存片段的实例
- javascript - 背景视频播放列表
- git - 如何管理多语言项目的位存储库
- ios - 如何通过页脚单元格在表格视图中使用委托?
- docker - 缺少高山包 py3-scipy
- jenkins - 詹金斯如何设置所有带有前缀“blah”的作业,以便在超过时间限制时停止
- ionic4 - toast.present() 在 Ionic 4 中失败
- mysql - 没有 MariaDB 引擎的 Ubuntu 19.04 上的 MySQL 服务器
- vb.net - 将 DLL 导入从 VB.NET 转换为 VB6