简体   繁体   中英

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. 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?

You can add any command line options in pytest.ini under addopts . In your case this should work:

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. From the output of pytest -h :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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