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 天前
AI 帮我写单测:pytest 覆盖率提升 40% 的协作日志
人工智能·pytest·测试驱动开发·代码覆盖率·ai协作开发
lucia_zl6 天前
pytest并发测试,资源问题导致用例失败解决办法
pytest
鱼鱼说测试6 天前
Selenium4+Pytest自动化测试框架实战
pytest
XYiFfang13 天前
【Pytest】解决Pytest中Teardown钩子的TypeError:实例方法与类方法的调用差异
python·pytest
Kingairy14 天前
Pytest 插件:pytest_runtest_protocol
python·pytest
AIZHINAN15 天前
Pytest 插件介绍和开发
测试工具·pytest·插件开发
灰阳阳17 天前
替身演员的艺术:pytest-mock 从入门到飙戏
自动化测试·python·pytest·unit testing·pytest-mock
年年测试20 天前
Playwright与PyTest结合指南
pytest
focksorCr20 天前
pytest 并发执行用例(基于受限的测试资源)
python·pytest