简体   繁体   English

排除 pytest 配置文件中的测试

[英]Exclude tests in pytest configuration file

I would like to be able to exclude instead of include certain python test files in the pytest.ini configuration file.我希望能够在pytest.ini配置文件中排除而不是包含某些 python 测试文件。 According to the docs including tests boils down to something like this:根据文档,包括测试归结为这样的事情:

# content of pytest.ini
[pytest]
pytest_files=test_main.py test_common.py

To exclude files however, only command line options are suggested:但是,要排除文件,建议仅使用命令行选项:

--ignore=test_common.py

How can I actually select files to ignore at the pytest.ini file level?如何在pytest.ini文件级别实际选择要忽略的文件?

You can add any command line options in pytest.ini under addopts .您可以添加任何命令行选项pytest.iniaddopts In your case this should work:在您的情况下,这应该有效:

pytest.ini pytest.ini

[pytest]
addopts = --ignore=test_common.py

As has been noted in the comments, --ignore takes a path (relative or absolute), not just a module name.正如评论中所指出的,-- --ignore采用路径(相对或绝对),而不仅仅是模块名称。 From the output of pytest -h :pytest -h的输出:

  --ignore=path         ignore path during collection (multi-allowed).
  --ignore-glob=path    ignore path pattern during collection (multi-allowed).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM