温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用pytest-dependency解决用例间的依赖问题

发布时间:2020-05-25 12:19:41 来源:网络 阅读:1470 作者:熊二的日常 栏目:软件技术

使用场景:测试B仅在测试A成功通过后方能有效进行。

使用pytest-dependency解决用例间的依赖问题

意思是:使用该插件可以标记一个test作为其他test的依赖,当依赖项执行失败时,那些依赖它的test将会被跳过。

-------------------------------------------------------------上实例:----------------------------------------------------------------

安装:pytest-dependency

pip install pytest-dependency


使用:

import pytest

@pytest.mark.dependency()
def test_01(test):
    assert False

@pytest.mark.dependency(depends=["test_01"])
def test_02(test):
    print("执行测试2")

看下结果:

使用pytest-dependency解决用例间的依赖问题

test_01是test_02的依赖,故而test_01失败后,test_02被跳过


结论:

1、首先安装这个插件,

2、使用方法就是用 @pytest.mark.dependency()对所依赖的方法进行标记,使用@pytest.mark.dependency(depends=["test_name"])引用依赖。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI