pytest+allure

知识点1:

1、测试结果信息阅读

  • passed表示通过,有个简写.

  • failed表示失败,有个简写F

2、命令行参数

  • -h:帮助

  • -version:版本信息

3、测试用例命名规则:

  • 测试函数必须以test开头

  • 测试类必须以Test开头,但测试类不能有init方法

  • 测试文件必须以test/Test开头,或者test/Test结尾

4、运行指定的测试用例:指定文件[::类名][::函数名]

  • 用例搜索的规则默认是pytest执行当前目录及子目录(遍历)

  • 指定类名运行:pytest 文件名::类名

  • 指定函数名运行:pytest 文件名::类名::函数名

  • 指定函数名运行:pytest 文件名::函数名

  • 指定目录下的文件运行:pytest 目录名\文件名::函数名

  • pytest .\test_a02\test_a02_a.py::test_001 (test_a02_a.py文件下的test_001 类;终端)

5、pytest.main()执行用例

  • 命令行参数args,列表类型,一个或多个str组成,逗号分隔
import pytest


def test_a01():
    assert 1 == 1


if __name__ == '__main__':  # 运行测试的话,需要在pycharm中设置python集成工具=>unittest
    # pytest.main()  # 等价于pytest命令
    # pytest.main([__file__])  # 测试当前文件
    # pytest.main(['--version'])
    pytest.main['-sv', __file__]  # 多参数调用

6、运行指定测试用例——k参数

  • 匹配测试类或测试方法的名字部分

  • 大小写敏感

  • 逻辑运算

表达式 说明
-k login 测试类名或函数名中包含login的用例
-k not login 不包含login的
-k login and success 包含login且包含success的
-k login or success 包含login或success的
-k login and not success 包含login且不包含success的
import pytest


def test_login_success():
    pass


def test_login_failed():
    pass


def test_logout_success():
    pass


def test_logout_failed():
    pass


if __name__ == '__main__':
    pytest.main(['-k success and not failed', '--collect-only', __file__])  # –collect-only 含义:展示给定配置下哪些测试用例会被运行

在这里插入图片描述

7、pytest.mark.skip/skipif

  • 有条件的忽略skipif
import pytest, sys


@pytest.mark.skipif(1 == 1, reason='if 1==1 skip this')  # 条件满足就忽略测试  reason:标注原因
def test_a01_1(reason='i wanna skip this case'):
    pass


@pytest.mark.skipif(1 == 2, reason='if 1==2 skip this')  # 条件不满足不会跳过
def test_a01_2():
    pass


@pytest.mark.skipif(sys.platform == 'linux', reason='if linux skip this')  # sys.platform 操作系统平台标识
def test_a01_3():
    pass


if __name__ == '__main__':
    pytest.main(['-sv', __file__])

在这里插入图片描述

  • 输出结果s
import pytest


@pytest.mark.skip
def test_a01_1(reason='i wanna skip this case'):
    pass


def test_a01_2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鹿快跑~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值