pytest 常用命令参数

-x 用例一旦失败或错误时就立即停止执行

共两条用例,运行第一条报错失败或报错,第二条就不会执行

pytest -vs -x test_pytest_study.py::TestCommon1

共2条用例,当执行到第一条失败时候,第二条不执行

--maxfail=num

当用例错误个数达到指定数量时,停止测试

pytest -vs --maxfail=2 test_pytest_study.py::TestCommon1

共3条用例,当执行到第一条和第二条都失败时候,第三条不执行

-k 用例方法关键字匹配

会根据模块模块名称、类名称、方法名称进行匹配 比如只想运行模块中包含关键字类中包含关键字login 或 方法包含关键字login pytest -vs -k login testcases/test_pytest_study.py

那么模块中的函数名称存在:login 会执行

模块中类名称存在:login 不区分大小写; 里面的所有用例会执行

模块类名称不包含login 但里面的方法名称包含login 也会执行

-v 打印详细日志 -s 打印输出日志 一般都一起使用 -vs

--collect-only 只收集用例,不执行用例

--help 其他参数可使用帮助命令查看

--reruns num 失败重跑 (需安装pytest-rerunfailures 插件)

安装插件:pip install pytest-rerunfailures

pytest -vs --reruns 2 test_login.py 失败了重跑2次

--html 生成html 报告(需安装pytest-html 插件)

pytest test_login.py --html ./reports/result.html

相关推荐
码路飞2 小时前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽4 小时前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
敏编程8 小时前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪9 小时前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook9 小时前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田1 天前
使用 pkgutil 实现动态插件系统
python
前端付豪1 天前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽1 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战1 天前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋1 天前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python