I have a setup.cfg
file that specifies default parameters to use for pytest
. While this is great for running tests on my whole package, I'd like to be able to ignore the setup.cfg
options when running tests on individual modules. Is there a way to easily do this?
The --ignore-glob option allows to ignore test file paths based on Unix shell-style wildcards. If you want to exclude test-modules that end with _01.py , execute pytest with --ignore-glob='*_01.py' .
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.
setup. cfg is a cheekily named Python package which supports providing all of a Python distribution's metadata and build configuration via the setup. cfg file at the base of the distribution's source tree, rather than in the setup.py script.
The pytestconfig fixture is a shortcut to request. config, and is sometimes referred to in the pytest documentation as “the pytest config object.” To see how pytestconfig works, you'll look at how to add a custom command-line option and read the option value from within a test.
This seems to do the trick on systems where /dev/null
exists.
pytest -c /dev/null specific/test/location
-c
tells pytest to ignore implicit configuration files and use the provided config instead. I am not sure if pytest trying to read it silently fails or considers it empty though.
Note that will not only override the location of the tests for you, but also any other configuration you may have in setup.cfg, e.g. coverage.
You can also create an empty pytest.ini
file in the current directory.
The config file discovery function will try to find a file matching this name first before looking for a setup.cfg
.
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