Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an option for pytest to ignore the setup.cfg file?

Tags:

python

pytest

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?

like image 342
jdmcbr Avatar asked Sep 07 '15 18:09

jdmcbr


People also ask

How do I ignore a file in pytest?

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

Where is pytest config file?

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.

What does setup CFG do?

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.

What is Pytestconfig?

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.


2 Answers

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.

like image 180
Andrei Avatar answered Oct 21 '22 05:10

Andrei


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.

like image 30
Jean-Marc Avatar answered Oct 21 '22 05:10

Jean-Marc