pytest特点与执行

pytest特点:

  用例语言是纯python

  不支持测试报告,但可以使用插件(pytest-html)

  可以不导入pytest模块执行测试用例

  兼容性强,可以执行unittest测试用例

  pytest --help 查看帮助

pytest命名规则:

  模块、函数、类与方法必须以test_开头

  如果是嵌套套件,外层套件可以不以test开头,但内含的模块必须以test_开头

定义测试用例的方式:

  模块.函数

  类.方法:类必须以test开头,方法用例也需要test开头

执行测试用例:

  pytest test_01.py

  pytest tsdir

  指定多个测试套件执行:pytest t1.py t2.py

  根据目录名执行:pytest suite1 suite2

  指定模块用例:tc/test_mod.py::TestClass::test_func

  模糊搜索:pytest -k test_name

  输出print 加 -s

 报告输出:

  安装pytest-html插件:pip install pytest-html

  执行 pytest test.py --html=报告文件路径

    举例:pytest test_01.py --html=result eport.html

    这种result文件生成两个文件,一个是html文件,一个是css样式文件

  报告集成css样式:

    pytest test_01.py --html=result eport.html --self-contained-html

  

  

原文地址:https://www.cnblogs.com/aiyumo/p/12367820.html