user32882
user32882

Reputation: 5877

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?

Upvotes: 14

Views: 19766

Answers (1)

MrBean Bremen
MrBean Bremen

Reputation: 16815

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

Upvotes: 20

Related Questions