命令行
以下内容为pytest的常用命令行执行命令,再这里进行汇总
pytest测试执行方面的命令行:
$ pytest -k <模糊搜索案例名> <以模糊搜索的方式搜索案例,并执行找到的测试案例>
$ pytest -s <执行测试的时候,打印详细的日志,所有的打印,都会打印到运行界面中>
$ pytest -h <查询测试案例的帮助信息>
$ pytest -m <只运行与给定标记表达式匹配的测试>
$ pytest -x --exitfirst <错误或测试失败时立即退出第一个>
$ pytest -x --maxfail=num <最大错误退出次数配置,超过这个个数,测试会退出>
$ pytest --continue-on-collection-errors <即使发生错误也会强制执行测试>
$ pytest --rootdir='ROOTDIR' <定义测试执行的根路径为'ROOTDIR'>
$ pytest --fixtures-per-test <每次执行都显示设备>
$ pytest --pdb <在出现错误或键盘终端时启动交互式Python调试器>
$ pytest --pdbcls=modulename:classname <在出现错误时自定义启动交互式Python调试器>
$ pytest --trace <每次测试时立即中断>
$ pytest --capture=method <每次测试捕获的方法 method=[fd|sys|no]>
$ pytest --runxfail <运行xfail的测试结果,就好像没有被标记一样>
$ pytest --lf, --last-failed <运行上一次运行失败的测试案例,如果没有失败案例,则会重新运行>
$ pytest --nf, --new-first <首先运行所有失败的案例,但是会从最后一个失败的案例开始运行,可能会重新进行排序>
$ pytest --cache-show=[CACHESHOW] <运行时显示缓存 可选参数=[glob(默认值为*)]>
$ pytest --cache-clear <在测试运行开始的时候删除所有缓存内容>
$ pytest --lfnf={all,none}, --last-failed-no-failures={all,none} <哪些案例是在已知失败下运行的>
$ pytest --sw, --stepwise <测试失败时退出,下次从上次失败的测试继续>
$ pytest --stepwise-skip <忽略第一个失败的测试,但在下雨给失败的测试时停止>
pytest测试报告方面的命令行:
$ pytest -v <执行测试的时候,打印案例的详细信息>
$ pytest -q <以静默的方式执行测试案例---不会打印任何内容>
$ pytest --verbosity=VERBOSE <设置详细信息>
$ pytest -r <字符> <显示字符指定的测试摘要信息 f=[失败] E=[错误] s=[中断] x=[失败] X=[通过] w=[警告] >
$ pytest --disable-warnings, --disable-pytest-warnings <禁用警告>
$ pytest -l, --showlocals <在回溯中显示局部变量(默认情况下禁用)>
$ pytest --tb=style <回溯打印模式 可选值=auto/long/short/line/native/no>
$ pytest --show-capture=<no,stdout,stderr,log,all> <控制捕获的stdout/stderr/log在失败测试中的显示方式,默认为“全部”>
$ pytest --full-trace <不剪切任何回溯,默认为剪切>
$ pytest --color=color <彩色端输出 (yes,no,outo)>
$ pytest --pastebin=mode<failed|all> <发送失败|所有信息到bpaste.net pastebin服务器>
$ pytest --junit-xml=path <在给定路径创建junit-xml样式的报告文件>
$ pytest --junit-prefix=str <在junit-xml输出中为类名添加前缀>
$ pytest --result-log=path <机器可读结果日志的路径 不推荐使用>
$ pytest --html=path <在给定路径创建html报告文件>
$ pytset --self-contained-html <创建一个包含所有必需样式、脚本和图像的自包含html文件>
pytest其它测试指令的命令行:
$ pytest --collect-only <只收集测试,不执行测试>
$ pytest --pyargs <尝试将所有参数解析为python包>
$ pytest --ignore=path <收集期间忽略路径,允许多个>
$ pytest --ignore-glob=path <收集期间忽略路径模式,允许多个>
$ pytest --deselect=nodeid_prefix <在收集期间取消选择项(通过节点id前缀)(允许多个)>
$ pytest --confcutdir=dir <仅相对于指定的目录加载conftest.py>
$ pytest --noconftest <不加载任何conftest.py文件>
$ pytest --keep-duplicates <保留重复测试>
$ pytest --collect-in-virtualenv <不要忽略本地virtualenv目录中的测试>
$ pytest --doctest-modules <在所有.py模块中运行doctests>
$ pytest --doctest-report={none,cdiff,ndiff,udiff,only_first_failure} <不要忽略本地virtualenv目录中的测试>
$ pytest --doctest-glob=pat <doctests文件匹配模式,默认:test*.txt>
$ pytest --doctest-continue-on-failure <对于给定的doctest,在第一次失败后继续运行>