使用命令行运行特定的用例的命令:pytest test_case1::test_case1
在main函数中会有参数的传递,需要传 list 类型,且都是以 list 结果来封装,以空格区分,每个空格都是单独参数。
在main函数中,多条指令运行时,需要通过逗号分割,例如:pytest.main(['-s', '-v'])
注意: pytest 默认不输出任何打印信息,需要运行时添加 -s 指令,
-
-v用于显示详细日志信息; -
-rA用于测试结果的简单统计;
前置、后置函数:
-
pytest中的
teardown、setup:一般可以通过配置文件进行管理,配置文件命名一定是conftest.py -
在class类中,前置后置函数运行顺序:
- setupclass
- tup_method
- setup
- test_case
- teardown
- teatdown method
- teardown class
pytest中用例的管理手段: mark
- 可以对mark装饰器对所有用例进行标记,不同的标记区分进行管理,如图:
命令行运行: pytest -s test_demo::test_case2.py -m webui,interui
框架核心配置文件: pytest.ini
框架的核心配置文件,配置在工程的根路径下,可以全局生效
python_files:自定义运行的py文件名称
python_classes:自定义命名运行的类的名称
testpaths:自定义运行路径 test_demo路径下的都会运行,即指定一个读取测试用例的路径
python_functions:自定义运行所有指定名称的函数
log_cli:配置日志
addopts:配置mian()中的参数 , -s,-v
pytest生成测试报告:
pytest-html测试报告模块 pytest --html=./report/report.html --self-contained-html
使用 --self-contained-html 不会生成assert文件夹
浙公网安备 33010602011771号