python笔记15--pytest学习

pytest学习资料:

详细的介绍pytest的应用方法,很有用的学习资料。
https://www.cnblogs.com/yoyoketang/tag/pytest/default.html?page=2

pytest 用例规则:

  1. 测试文件以test_开头(以_test结尾也可以)
  2. 测试类以Test开头,并且不能带有 init 方法
  3. 测试函数以test_开头
  4. 断言使用assert

pytest 执行case命令:

  1. 运行目录及子包下的所有用例:
pytest 目录名
  1. 运行执行某一个py文件下用例:
 pytest test.py
  1. 按节点运行:
    运行.py模块里面的某个函数
pytest test_mod.py::test_func

运行.py模块里面,测试类里面的某个方法

pytest test_mod.py::TestClass::test_method
  1. 按标记执行:
pytest -m slow
将运行用@ pytest.mark.slow装饰器修饰的所有测试。
只运行含标签wwan的case:pytest -v -m wwan
运行不含标签wwan的case: pytest -v -m "not wwan"
同时运行wwan和ezconfig标签的case: pytest -v -m wwan and ezconfig
  1. 运行fail失败的case:
pytest  --lf
pytest xx1.py xx2.py --lf  (执行xx1.py和xx2.py上次fail的用例)

生成html报告:

pytest -v --html=report.html

生成allure报告:

pytest --alluredir ./report/allure_raw

打开html的报告需要启动allure服务,启动命令如下:

allure serve  xxx/report/allure_raw

html报告和allure报告均生成:

pytest --html=report.html --alluredir ./report/allure_raw
pytest xx1.py --html=report.html --alluredir ./report/allure_raw
pytest xx1.py xx2.py --lf --html=report.html --alluredir ./report/allure_raw   (执行fail的case, allure报告会两次汇总为一份报告)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值