网站空间可以自己做服务器,网站环境搭建教程,福州营销型网站建设,自己在线制作图片免费下载我们一般在做自动化测试时#xff0c;用例设计之间应该是可以相互独立执行的#xff0c;没有一定的前后依赖关系的#xff0c;如果我们真的有前后依赖#xff0c;想指定用例的先后顺序#xff0c;可以用到pytest-ordering插件解决这个问题
1、安装依赖包 pip install pyt…我们一般在做自动化测试时用例设计之间应该是可以相互独立执行的没有一定的前后依赖关系的如果我们真的有前后依赖想指定用例的先后顺序可以用到pytest-ordering插件解决这个问题
1、安装依赖包 pip install pytest-ordering
2、运用 用例方法上添加装饰器pytest.mark.run(order2)用例执行顺序会以order值大小升序去调用执行
3、先按Pytest默认执行顺序根据用例的先后顺序先执行了用例1test_login_01再执行了用例2test_login_02
#!/usr/bin/env python
# _*_coding:utf-8_*_
import pytestclass Test(object):def test_login_01(self):用例1print(执行用例test_login_01断言1)pytest.assume(1 1)print(执行用例test_login_01断言2)pytest.assume(2 2)def test_login_02(self):用例2print(执行用例test_login_02断言1)pytest.assume(3 3)print(执行用例test_login_02断言2)pytest.assume(True)if __name__ __main__:pytest.main([-s, test_C_01.py])C:\Users\admin\AppData\Local\Programs\Python\Python37\python.exe C:/Users/admin/Desktop/AutoTest/Test/test/test_C_01.pytest session starts
platform win32 -- Python 3.7.4, pytest-5.4.2, py-1.8.1, pluggy-0.13.1
rootdir: C:\Users\admin\Desktop\AutoTest\Test\test
plugins: assume-2.2.1, ordering-0.6
收集的测试用例:[Function test_login_01, Function test_login_02]
collected 2 itemstest_C_01.py 执行用例test_login_01断言1
执行用例test_login_01断言2
.执行用例test_login_02断言1
执行用例test_login_02断言2
. 2 passed in 0.04s Process finished with exit code 0
4、设置了用例先后顺序为est_login_01pytest.mark.run(order2)、test_login_02pytest.mark.run(order1)调用后先执行了用例2test_login_02再执行了用例1test_login_01
#!/usr/bin/env python
# _*_coding:utf-8_*_
import pytestclass Test(object):pytest.mark.run(order2)def test_login_01(self):用例1print(执行用例test_login_01断言1)pytest.assume(1 1)print(执行用例test_login_01断言2)pytest.assume(2 2)pytest.mark.run(order1)def test_login_02(self):用例2print(执行用例test_login_02断言1)pytest.assume(3 3)print(执行用例test_login_02断言2)pytest.assume(True)if __name__ __main__:pytest.main([-s, test_C_01.py])C:\Users\admin\AppData\Local\Programs\Python\Python37\python.exe C:/Users/admin/Desktop/AutoTest/Test/test/test_C_01.pytest session starts
platform win32 -- Python 3.7.4, pytest-5.4.2, py-1.8.1, pluggy-0.13.1
rootdir: C:\Users\admin\Desktop\AutoTest\Test\test
plugins: assume-2.2.1, ordering-0.6
收集的测试用例:[Function test_login_01, Function test_login_02]
collected 2 itemstest_C_01.py 执行用例test_login_02断言1
执行用例test_login_02断言2
.执行用例test_login_01断言1
执行用例test_login_01断言2
. 2 passed in 0.06s Process finished with exit code 0