pytest学习资料:
详细的介绍pytest的应用方法,很有用的学习资料。
https://www.cnblogs.com/yoyoketang/tag/pytest/default.html?page=2
pytest 用例规则:
- 测试文件以test_开头(以_test结尾也可以)
- 测试类以Test开头,并且不能带有 init 方法
- 测试函数以test_开头
- 断言使用assert
pytest 执行case命令:
- 运行目录及子包下的所有用例:
pytest 目录名
- 运行执行某一个py文件下用例:
pytest test.py
- 按节点运行:
运行.py模块里面的某个函数
pytest test_mod.py::test_func
运行.py模块里面,测试类里面的某个方法
pytest test_mod.py::TestClass::test_method
- 按标记执行:
pytest -m slow
将运行用@ pytest.mark.slow装饰器修饰的所有测试。
只运行含标签wwan的case:pytest -v -m wwan
运行不含标签wwan的case: pytest -v -m "not wwan"
同时运行wwan和ezconfig标签的case: pytest -v -m wwan and ezconfig
- 运行fail失败的case:
pytest --lf
pytest xx1.py xx2.py --lf (执行xx1.py和xx2.py上次fail的用例)
生成html报告:
pytest -v --html=report.html
生成allure报告:
pytest --alluredir ./report/allure_raw
打开html的报告需要启动allure服务,启动命令如下:
allure serve xxx/report/allure_raw
html报告和allure报告均生成:
pytest --html=report.html --alluredir ./report/allure_raw
pytest xx1.py --html=report.html --alluredir ./report/allure_raw
pytest xx1.py xx2.py --lf --html=report.html --alluredir ./report/allure_raw (执行fail的case, allure报告会两次汇总为一份报告)