微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

【pytest】四 pytest的一些其他的运行用法

1. 可以设置当失败N个后停止测试

pytest -x 是当第一个失败产生后,停止
pytest --maxfail=2, 这里就是当失败2个用例后,停止测试

2.pytest 在命令行模式下支持多种方式运行和选择运行

  • pytest test_mod.py 运行这个文件(模块)
  • pytest testing/ 运行指定目录下的测试文件

3. 指定运行文件下具体类下的具体方法,用:: 分隔 文件、类、 方法

pytest test_mod.py::TestClass::test_method

4.pytest中同样提供了main() 来函数来执行测试用例

@H_404_19@import pytest def test_main(): assert 5 != 5 if __name__ == '__main__': pytest.main()

sublime,ctrl + b 即可运行

5.在main()下运行指定目录文件,也可以加参数,比如

@H_404_19@import pytest def test_main(): assert 5 != 5 if __name__ == '__main__': pytest.main("d:/pyse/pytest/") # 指定测试目录

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐