Skip to main content

Continuous integration in Python 3: set up your test configuration files

This is the third post in my series on continuous integration (CI) in Python. For the first two posts, see 1: automated tests with pytest, and 2: measuring test coverage.

By now, you've got a bunch of tests and doctests set up in your project, which you run with the command:

$ py.test --doctest-modules --cov . --cov-report term-missing

If you happen to have a few script and setup files lying around that you don't want to test, this might expand to

$ py.test --doctest-modules --cov . --cov-report term-missing --ignore script.py

As you can see, this is getting cumbersome. You can fix this by adding a setup.cfg file to the root of your project, containing configuration options for your testing. This follows standard INI file syntax.

[pytest]
addopts = --ignore script.py --doctest-modules --cov-report term-missing --cov .

Note that the "ignore" flag only tells pytest not to run that file during testing. You also have to tell the coverage module that you don't want those lines counted for coverage. Do this in a .coveragerc file, with similar syntax:

[run]
omit = *script.py

Once you've done this, you can invoke your tests with a simple, undecorated call to just py.test.

To find out more about your configuration options, see the pytest basic test configuration page, and Ned Batchelder's excellent .coveragerc syntax guide.

That's it for this entry of my CI series. Follow this blog for the next two entries, setting up Travis CI and Coveralls.

Update: Volume 4: Set up Travis-CI

Comments

Comments powered by Disqus