pytest 用例执行顺序

简介: pytest 用例执行顺序

默认执行顺序从上到下

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'])

相关文章
|
5天前
|
测试技术
Pytest参数化用例
`Pytest`的参数化功能用于通过参数生成和执行多个测试用例。使用`@pytest.mark.parametrize`装饰器,可传入不同数据,如单参数或多个参数,并可设置`ids`为用例命名。例如,一个搜索功能测试会根据提供的关键词列表动态生成用例。另外,通过创建`conftest.py`文件并定义函数,可以显示中文用例名称。同时,可以利用笛卡尔积实现更复杂的参数组合。
4 0
|
9月前
|
测试技术 Python
Pytest用例执行的先后顺序
Pytest用例执行的先后顺序
93 0
|
10月前
|
测试技术
15-pytest-自定义用例执行顺序
15-pytest-自定义用例执行顺序
|
10月前
|
测试技术
30-pytest-重复执行用例-pytest-repeat
30-pytest-重复执行用例-pytest-repeat
30-pytest-重复执行用例-pytest-repeat
|
10月前
|
测试技术
34-pytest-Hooks函数之获取用例执行结果
34-pytest-Hooks函数之获取用例执行结果
|
10月前
|
测试技术 Python
02-pytest-用例运行规则
02-pytest-用例运行规则
|
测试技术 Python
pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
104 0
pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
|
测试技术 C++
Pytest框架测试用例规则和运行方式
Pytest框架测试用例规则:模块名:必须以 test_开头 或者 _test结尾;测试类:必须以 Test开头,并且不能有init方法;测试方法:必须以 test开头。Pytest框架测试运行模式:主函数模式、命令行模式、通过读取配置文件pytest.ini运行。。。
215 0
Pytest框架测试用例规则和运行方式
|
测试技术
pytest学习和使用14-Pytest用例执行结果有哪几种状态?
pytest学习和使用14-Pytest用例执行结果有哪几种状态?
77 0
|
测试技术 Python
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
72 0
pytest学习和使用10-Pytest中的测试用例如何跳过执行?