Pytest:通过命令行自定义测试发现

Pytest: customize test discovery through command line

有一些方法可以通过configuration file 配置pytest测试发现。

我想知道是否有办法通过命令行配置 pytest 测试发现 options/args。换句话说,我可以通过一些 argument/switch 到 pytest 命令来实现这个吗?

您放入配置文件的每个条目(so-called“inioption”)都可以使用-o/--override-ini选项从命令行传递。 -o 选项可以多次应用。例如

$ pytest -o python_files='check_*.py' \
         -o python_classes=Check \
         -o python_functions='*_check'

来源:Configuration Options.