pytest pytest.ini配置 用例分组 用例跳过

简介: pytest pytest.ini配置 用例分组 用例跳过

一.pytest.ini配置


1.文件位置,根目录下

addopts = -vs 配置默认携带的参数

testpaths = ./basics 配置默认执行用例的目录

配置用例分组的便签名

markers =

smoke:冒烟用例

huigui:回归用例


2.文件格式编码

使用工具变成ANSI编码,不然无法读取配置文件

二.用例分组

代码

@pytest.mark.run(order=1)
这条只属于冒烟用例
@pytest.mark.smoke
def test1():
    print('登录')
@pytest.mark.run(order=4)
def test4():
    print('取件')
@pytest.mark.skip(reason="说明跳过原因")
def test_skip():
    print("测试跳过这条用例")
这条被设置为2个分组,属于冒烟和回归
@pytest.mark.run(order=2)
@pytest.mark.huigui
@pytest.mark.smoke
def test2():
    print('存件')
age=17
@pytest.mark.run(order=3)
这条只属于冒烟用例
@pytest.mark.huigui
@pytest.mark.skipif(age<18,reason="未成年人不需要发短信")
def test3():
    print('发短信')

执行

1.只执行冒烟

pytest.main([r'D:\python新代码集\pytest_study\basics\test_execution_sequence.py','-m smoke'])

2.只执行回归

pytest.main([r'D:\python新代码集\pytest_study\basics\test_execution_sequence.py','-m huigui'])

3.执行冒烟和回归的交集

    pytest.main([r'D:\python新代码集\pytest_study\basics\test_execution_sequence.py','-m huigui and smoke'])

4.执行冒烟和回归的并集

    pytest.main([r'D:\python新代码集\pytest_study\basics\test_execution_sequence.py','-m huigui or smoke'])


三.用例跳过

知识点

无条件跳过加上跳过原因

@pytest.mark.skip(reason="说明跳过原因")
def test_skip():
    print("测试跳过这条用例")

有条件跳过加上判断条件,满足条件就跳过

age=17
@pytest.mark.run(order=3)
@pytest.mark.huigui
@pytest.mark.skipif(age<18,reason="未成年人不需要发短信")
def test3():
    print('发短信')

代码

@pytest.mark.run(order=1)
@pytest.mark.smoke
def test1():
    print('登录')
@pytest.mark.run(order=4)
def test4():
    print('取件')
@pytest.mark.skip(reason="说明跳过原因")
def test_skip():
    print("测试跳过这条用例")
@pytest.mark.run(order=2)
@pytest.mark.huigui
@pytest.mark.smoke
def test2():
    print('存件')
age=17
@pytest.mark.run(order=3)
@pytest.mark.huigui
@pytest.mark.skipif(age<18,reason="未成年人不需要发短信")
def test3():
    print('发短信')

执行

不需要什么参数直接执行就行

相关文章
|
6天前
|
测试技术
Allure2添加用例标题、用例步骤
在Allure2报告中,可以通过`@allure.title`装饰器添加用例标题以增强可读性。标题可参数化或动态更新。同时,Allure2支持两种添加步骤方法:1) 使用`@allure.step`定义测试步骤并在用例中调用;2) 使用`with allure.step()`结构在代码块中添加步骤,提高测试流程的清晰度。这些功能提升了报告的易读性和测试的详细度。
9 3
|
9月前
|
测试技术 Python
pytest--运行指定的测试和参数化
pytest--运行指定的测试和参数化
|
10月前
|
测试技术 Python
02-pytest-用例运行规则
02-pytest-用例运行规则
|
10月前
|
测试技术
16-pytest-skip跳过用例
16-pytest-skip跳过用例
|
10月前
|
测试技术
15-pytest-自定义用例执行顺序
15-pytest-自定义用例执行顺序
|
测试技术 C++
Pytest框架测试用例规则和运行方式
Pytest框架测试用例规则:模块名:必须以 test_开头 或者 _test结尾;测试类:必须以 Test开头,并且不能有init方法;测试方法:必须以 test开头。Pytest框架测试运行模式:主函数模式、命令行模式、通过读取配置文件pytest.ini运行。。。
216 0
Pytest框架测试用例规则和运行方式
|
测试技术
pytest学习和使用14-Pytest用例执行结果有哪几种状态?
pytest学习和使用14-Pytest用例执行结果有哪几种状态?
77 0
|
测试技术 Python
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
72 0
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
|
测试技术
pytest二位元组方式获取测试用例
二次封装测试用例读取方式
87 0
|
测试技术 Python
python中pytest收集用例规则与运行指定用例详解
python中pytest收集用例规则与运行指定用例详解
160 0