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?
The simplest way to skip a test function is to mark it with the skip decorator which may be passed an optional reason : @pytest. mark.
Many pytest settings can be set in a configuration file, which by convention resides on the root of your repository or in your tests folder.
Running pytest We can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests. A marked grouped of tests is then run with pytest -m .
Users can customize some pytest behavior using a configuration file called pytest. ini . This file is usually placed at the root of the repository and contains a number of configuration values that are applied to all test runs for that project.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With