pytest --version # shows where pytest was imported from pytest --fixtures # show available builtin function arguments pytest -h | --help # show help on command line and config file options
分析测试执行时间
1
pytest --durations=10 --durations-min=1.0
获得1.0 s 长度内最慢的10个测试持续时间列表 默认情况下,pytest 不会显示太小的测试持续时间(< 0.005 s) ,除非在命令行上传递-vv
管理插件的加载
提前加载插件 通过-p 命令提前加载插件
1
pytest -p mypluginmodule
不加载插件
1
pytest -p no:mypluginmodule
其他调用pytest的方式
python解释器
1
python -m pytest [...]
通过main函数
1
retcode = pytest.main()
添加插件
1 2 3 4 5 6 7 8 9 10
import sys
import pytest
class MyPlugin: def pytest_sessionfinish(self): print("*** test run reporting finishing")
if __name__ == "__main__": sys.exit(pytest.main(["-qq"], plugins=[MyPlugin()]))