测试用例规则:
测试文件以test_开头(以_test结尾也可以)
测试类以Test开头,并且不能带有 init 方法
测试函数以test_开头
断言使用基本的assert即可
所有的包pakege必须要有__init__.py文件
#创建JUnitXML格式文件(可被Jenkins或其他持续集成服务器读取的结果文件)
pytest --junitxml=path
#创建纯文本机器可读的结果文件,计划在pytest 6.0中删除
pytest --resultlog=path
#生成html报告
pytest --html=report.html
#设置断点
import pdb;pdb.set_trace()
#要在第一个(N)次失败后停止测试过程:
pytest -x # stop after first failure
pytest --maxfail=2 # stop after two failures
#在模块中运行测试
pytest test_mod.py
#在目录中运行测试
pytest testing/
#通过关键字表达式运行测试
#这将运行包含与给定的字符串表达式匹配的名称(不区分大小写)的测试,其中可以包括使用文件名,类名
#和函数名作为变量的Python运算符。上面的示例将运行,TestMyClass.test_something
#但不会运行TestMyClass.test_method_simple。
pytest -k “MyClass and not method”
#命令行中指定测试方法
pyt