1、pytest加载全部的用例都是乱序的,若是想指定用例的顺序,能够使用pytest-ordering插件,指定用例的执行顺序只须要在测试用例的方法前面加上装饰器@pytest.mark.run(order=[num])设置order的对应的num值,它就能够按照num的大小顺序来执行。html
应用场景:有时运行测试用例要指定它的顺序,好比有些场景要先须要登入,才能执行后面的流程好比购物流程,下单流程,这时就须要指定用例的执行顺序。经过pytest-ordering这个插件能够完成用例顺序的指定。python
2、安装session
pip install pytest-ordering测试
3、实例spa
#!/usr/bin/env python # _*_coding: utf-8 _*_ import pytest class Testpytest(object): @pytest.mark.run(order=-1) def test_two(self): print("test_two, 测试用例") @pytest.mark.run(order=3) def test_one(self): print("test_one, 测试用例") @pytest.mark.run(order=1) def test_three(self): print("test_three, 测试用例")
四运行结果插件
Testing started at 15:51 ... C:\Python\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1\helpers\pycharm\_jb_pytest_runner.py" --path C:/Users/wanwen/PycharmProjects/vigo/xuexi/20210123/test_order.py Launching pytest with arguments C:/Users/wanwen/PycharmProjects/vigo/xuexi/20210123/test_order.py in C:\Users\wanwen\PycharmProjects\vigo\xuexi\20210123 ============================= test session starts ============================= platform win32 -- Python 3.8.0, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 rootdir: C:\Users\wanwen\PycharmProjects\vigo\xuexi\20210123 plugins: html-2.1.1, metadata-1.11.0, ordering-0.6collected 3 items test_order.py [100%] ============================== 3 passed in 0.06s ============================== Process finished with exit code 0 .test_three, 测试用例 .test_one, 测试用例 .test_two, 测试用例