[pytest-废物笔记]python-pytest+allure学习笔记

此仅记录本人在pytest和allure的学习笔记

pytest命名规则

  • 文件名:test__test开头或结尾
  • 类:默认以Test开头普
  • function:默认以test_开头
    注:文件名不以test__test开头或结尾运行时会提示找不到文件
ERROR: file or directory not found: estlogincase.py

测试固件

测试固件解释
setup_module/teardown_module模块开始或结束运行一次
setup_function/teardown_function函数开始或结束运行一次
setup_class/teardown_class类开始或结束运行一次
setup_method/teardown_method方法开始或结束运行一次
setup/teardow开始或结束运行一次

注:当定义了类后使用setup_class/teardown_class ,setup_method/teardown_method ,不使用类时使用setup_module/teardown_module,setup_function/teardown_function否则不会运行

pytest的执行

使用pytest.mian执行脚本

调用参数解释
pytest.main([‘-s’])执行命令文件所在文件中所有复合条件的用例
pytest.main([‘-s’,‘test.py’])仅执行test.py下的用例
pytest.main([‘-s’,‘test.py::Test01’])执行test.py下Test 01类的用例
pytest.main([‘-s’,‘test.py’,‘–reruns 2’])失败后重新运行2次
pytest.main([‘-s’,‘test.py’,‘–reruns 2’,‘–reruns-delay 2’])失败后重新运行2次,每次等待2秒
@pytest.mark.L1将用例标记为L1等级
pytest.main([‘-s’,‘test.py’,‘-m L1’])仅执行标记为L1的用例
pytest.main([‘-s’,‘test.py’,‘-m L1 or L2’])仅执行标记为L1或L2的用例
@pytest.skip(reason=“跳过原因”)无条件跳过
@pytest.skipif(跳过条件,reason=“跳过原因”)条件为true时,跳过

pytest参数化

基本格式:
data=[(‘admin’,‘pwd’,‘123’),((‘admin1’,‘pwd1’,‘1234’)]
类外使用
@pytest.mark.parametrize((‘参数对应函数名1’,‘参数对应函数名2’,‘参数对应函数名3’),data)

allure参数

参数解释
@allure.feature(“”)标记功能模块一般在类上使用
@allure.story(“”)标记功能模块一般在方法上使用
@allure.step(“”)标记测试步骤
@allure.severity(“”)用例重要级别:blocker致命,critical严重,normal一般(默认),minor次要,trivial轻微

allure 调用

pytest.main([‘-s’,‘test.py’,‘–allure’,‘./report’])
在report文件下生成allure报告的json数据
命令行输入allure generated --clean report 清除上次报告数据后生成html报告

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值