默认执行顺序从上到下
import pytest def test1(): print('登录') def test4(): print('取件') def test2(): print('存件') def test3(): print('发短信') if __name__ == '__main__': pytest.main(['-vs',r'D:\python新代码集\pytest_study\basics\test_execution_sequence.py'])
这里需要安装我上篇文章改用例执行顺序的插件
通过@pytest.mark.run(order=1)控制执行顺序
import pytest ''' 默认执行顺序从上到下 ''' @pytest.mark.run(order=1) def test1(): print('登录') @pytest.mark.run(order=4) def test4(): print('取件') @pytest.mark.run(order=2) def test2(): print('存件') @pytest.mark.run(order=3) def test3(): print('发短信') if __name__ == '__main__': pytest.main(['-vs',r'D:\python新代码集\pytest_study\basics\test_execution_sequence.py'])