Pytest--- 用例识别与运行

用例编写规范:

  1. 文件名以test_开头,或者以_test结尾
  2. 测试类以Test开头
  3. 测试方法以test_开头

  

  用例的运行

  •   命令行运行
  1. pytest test_demo.py
  2. pytest test_demo.py::TestDemo
  3. pytest test_demo.py::TestDemo::test_1
  • Pycharm 界面运行
  • 右键文件/目录运行

  运行结果: F代表用例失败,.代表用例通过

 Pytest命令行参数

  1. pytest --help: 查看帮助文档
  2. pytest -v: 打印详细运行日志
  3. pytest -s: 打印print信息
  4. pytest -k: 跳过运行某个或某些测试用例
  5. pytest -x:遇到执行失败的用例立刻停止运行
  6. pytest -- maxfail=1: 遇到1条失败的用例就停止运行
  7. pytest -m mark标签:只执行加有该标签的测试用例
  8. pytest --collect-only: 只收集测试用例
  9. pytest --junit-xml=./result.xml: 将执行的结果生成xml 文件

     

     以上就是命令行运行测试用例时经常使用到的参数,这些参数不仅可以单独使用,也可以组合一起使用(pytest -vs) 

posted @ 2021-12-01 11:34  ElsaWang  阅读(195)  评论(0)    收藏  举报