pip install pytest
pytest会递归查找当前目录及子目录下所有 以test_开始 或者 _test结尾的python脚本,执行其中符合规则的函数和方法,不需要显示调用
指令 | 含义 | 需要另安装插件 |
pytest folder_name | 直接运行文件夹内符合规则的所有用例 | |
pytest test_file.py | 执行某个py文件中的用例 | |
pytest test_file.py::test_func | 执行模块内的某个函数(节点运行) | |
pytest test_file.py::TestClass::test_method | 执行模块内测试类的某个方法(节点运行) | |
pytest test_file.py::TestClass | 执行模块内某个测试类(节点运行) | |
pytest test_file.py::TestClass test_file2.py::test_mothod | 多节点运行,中间用空格隔开 | |
pytest -k pass | 匹配用例名称的表达式,含有“pass”的被执行,其他的deselected | |
pytest -k "pass or fail" | 组合匹配,含有“pass” 和 “fail”的被执行 | |
pytest -k "not pass" | 排除运行,不含“pass”的被执行 | |
pytest -m finished | 标记表达式,运行用@pytest.mark.finished 标记的用例 | |
pytest -m "finished and not merged" | 多个标记逻辑匹配,运行含有finished 不含 merged标记的用例 | |
pytest -v | 运行时显示详细信息 | |
pytest -s | 显示打印消息 | |
pytest -x | 遇到错误就停止运行 | |
pytest -x --maxfail=2 | 遇到两个错误就停止运行 | |
pytest --setup-show | 跟踪固件运行 | |
pytest -v --reruns 5 --reruns-delay 1 | 运行失败的用例间隔1s重新运行5次 | pip install pytest-rerunfailures |
pytest | 多条断言,报错后,后面的依然执行 | pip install pytest-assume,断言 pytest.assume(2==4) |
pytest -n 3 | 3个cpu并行执行测试用例,需保证测试用例可随机执行 | pip install pytest-xdist分布式执行插件,多个cpu或主机执行 |
pytest -v -n auto | 自动侦测系统里cpu的数目 | |
pytest --count=2 | 重复运行测试 pip install pytest-repeat | |
pytest --html=./report/report.html | 生成报告,此报告中css是独立的,分享时会丢失样式 | pip install pytest-html |
pytest --html=report.html --self-containd-html | 合并css到html报告中,除了passed所有行都被展开 |
pytest folder_name | 直接运行文件夹内符合规则的所有用例 |
原文:https://www.cnblogs.com/belle-ls/p/12712462.html