pytest入门五:命令行参数

-v:一般在调试的时候加上这个参数,端会打印出每条用例的详细日志信息,方便定位问题

-s:当你的代码里面有print输出语句,如果想在运行结果中打印print输出的代码(默认控制台是不输出打印结果的),在运行的时候可以添加 -s 参数,一般在调试的时候使用

-k:只执行含有某个关键字的测试用例

复制代码
pytest -k "类名"
pytest -k "方法名"
pytest -k "类名 and not 方法名"

-m:将运行有 @pytest.mark.[标记名] 这个标记的测试用例

-x:遇到用例失败立即停止运行

--maxfail:用例失败个数达到阈值停止运行

复制代码
pytest --maxfail x

pytest -v -s test.py

pytest -v -s -x test.py 或者

pytest -v -s --maxfail 1 test.py

pytest -v -s -m add test.py

复制代码
if __name__ == "__main__":
    pytest.main(['-v', '-s','-m add','test.py'])

pytest -v -s -k "test_mark" test.py

相关推荐
测试开发技术4 小时前
软件测试中,pytest 如何运行多个文件或整个目录?
自动化测试·pytest·接口测试·面试题
鱼骨不是鱼翅3 天前
自动化框架pytest
运维·自动化·pytest
2025年一定要上岸6 天前
【pytest高阶】-2- 内置hook插件扩展机制和定制开发
pytest
2025年一定要上岸8 天前
【pytest高阶】源码的走读方法及插件hook
运维·前端·python·pytest
惜.己10 天前
pytest中使用ordering控制函数的执行顺序
开发语言·python·pytest
惜.己11 天前
pytest中使用skip跳过某个函数
开发语言·python·测试工具·pytest
程序员小远11 天前
Pytest+Selenium UI自动化测试实战实例
自动化测试·软件测试·python·selenium·测试工具·ui·pytest
惜.己13 天前
pytest简单使用和生成测试报告
开发语言·python·pytest
better-tomorrow13 天前
pytest-log
pytest
别在内卷了16 天前
测试学习之——Pytest Day4
python·学习·pytest