目录
1.pytest命名规范
- py文件要以test_开头,或者_test结尾
- 类要以Test开头,方法要以test_开头
2.pytest运行方式
- pychram界面运行
- 右键文件/目录运行
- 使用命令行的方式运行
3.pytest常用的执行参数
- pytest 模块名(执行模块中test_开头的方法)
- pytest --collect-only (只收集用例)
- pytest -k “add ”(匹配所有名称中包含add的用例)
- pytest -m 自定义的标记名(@pytest.mark.自定义标记名)
- pytest - - junitxml=./result.xml(生成执行结果文件)
- pytest --setup-show (回溯fixture的执行过程)
4.pytest框架结构
- 模块级(setup_module/teardown_module)模块始末,全局的(优先级最高)
- 函数级(setup_function/teardown_function)只对函数用例生效(不在类中)
- 类级(setup_class/teardown_class)在类中前后运行一次(在类中)
- 方法级(setup_method/t