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

  

<强>使用场景:测试B仅在测试一个成功通过后方能有效进行。

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

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

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

<强>安装:pytest-dependency

pip安装pytest-dependency

<强>

<强>使用:

进口pytest      @pytest.mark.dependency ()   def test_01(测试):   维护错误      @pytest.mark.dependency(取决于=(“test_01”))   def test_02(测试):   打印(“执行测试2”)

看下结果:

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

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


<强>结论:

1,首先安装这个插件,

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


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