网站运营策划ppt,东莞品牌网站定制,东莞公司网站价格,海外高延迟服务器做网站pytest.ini#xff1a;pytest的主配置文件#xff0c;可以改变pytest的默认行为conftest.py#xff1a;测试用例的一些fixture配置 pytest.ini marks
mark 打标的执行 pytest.mark.add add需要些marks配置否则报warning
[pytest]
markersadd:测试打标 测试用例中添加了 p… pytest.inipytest的主配置文件可以改变pytest的默认行为conftest.py测试用例的一些fixture配置 pytest.ini marks
mark 打标的执行 pytest.mark.add add需要些marks配置否则报warning
[pytest]
markersadd:测试打标 测试用例中添加了 pytest.mark.webtest 装饰器如果不添加marks选项的话就会报warnings [pytest] markers smoke end fist xfail_strict 设置xfail_strict True可以让那些标记为pytest.mark.xfail但实际通过显示XPASS的测试用例被报告为失败 addopts addopts参数可以更改默认命令行选项这个当我们在cmd输入一堆指令去执行用例的时候就可以用该参数代替了省去重复性的敲命令工作 # 命令行参数 addopts -v --reruns1 --count2 --htmlreports.html --self-contained-html -nauto 加了addopts之后我们在cmd中只需要敲pytest就可以生效了 log_cli 控制台实时输出日志 格式log_cliTrue 或False默认或者log_cli1 或 0 norecursedirs pytest 收集测试用例时会递归遍历所有子目录包括某些你明知道没必要遍历的目录遇到这种情况可以使用 norecursedirs 参数简化 pytest 的搜索工作 pytest默认的测试用例收集规则 ;指定测试目录 ;定义执行的目录 testpathstests ;自定义测试文件命名规则 python_files test_* check_* ;自定义测试类 python_classes Test* Check* ;自定义测试方法 python_functions test_* check_* ;指定特定路径:当在上级路径时也会默认执行sub_demo ;testpaths sub_demo ;忽略路径 norecursedirs result logs datas 指定pytest最低版本号 minversion5.0 conftest.py conftest.py import pytest pytest.fixture() def conftest_fixture(): print(fixture前置) yield print(fixture后置) test_demo.py def test_case(conftest_fixture): print(测试用例) 运行结果 test session starts collecting ... collected 1 item test_demo.py::test_case fixture前置 PASSED [100%]测试用例 fixture后置 1 passed in 0.02s