Pytest--- 用例识别与运行
用例编写规范:
- 文件名以test_开头,或者以_test结尾
- 测试类以Test开头
![]()
- 测试方法以test_开头

用例的运行
-
命令行运行
- pytest test_demo.py
- pytest test_demo.py::TestDemo
- pytest test_demo.py::TestDemo::test_1
-
Pycharm 界面运行
-
右键文件/目录运行
运行结果: F代表用例失败,.代表用例通过
Pytest命令行参数
- pytest --help: 查看帮助文档
- pytest -v: 打印详细运行日志
![]()
- pytest -s: 打印print信息
![]()
- pytest -k: 跳过运行某个或某些测试用例
![]()
- pytest -x:遇到执行失败的用例立刻停止运行
![]()
- pytest -- maxfail=1: 遇到1条失败的用例就停止运行
![]()
- pytest -m mark标签:只执行加有该标签的测试用例
- pytest --collect-only: 只收集测试用例
![]()
- pytest --junit-xml=./result.xml: 将执行的结果生成xml 文件
以上就是命令行运行测试用例时经常使用到的参数,这些参数不仅可以单独使用,也可以组合一起使用(pytest -vs)








浙公网安备 33010602011771号