我希望能够排除,而不是在pytest.ini
配置文件中包含某些python测试文件。根据包括测试在内的文档,可以归结为以下内容:
# content of pytest.ini
[pytest]
pytest_files=test_main.py test_common.py
然而,要排除文件,只建议使用命令行选项:
--ignore=test_common.py
如何在pytest.ini
文件级别选择要忽略的文件?
您可以在addopts
下的pytest.ini
中添加任何命令行选项。在您的情况下,这应该有效:
pytest.ini
[pytest]
addopts = --ignore=test_common.py
正如在评论中所指出的,--ignore
采用一个路径(相对或绝对(,而不仅仅是一个模块名称。来自pytest -h
:的输出
--ignore=path ignore path during collection (multi-allowed).
--ignore-glob=path ignore path pattern during collection (multi-allowed).