Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.coveragerc file location when running py.test

I am trying to get a pytest run to work with a coveragerc file. Settings in my .coveragerc file are not used, so I guess the file is not used at all.

See my project structure and pytest calls below! What am I doing wrong?

Project:

basepath/lib/
basepath/.coveragerc
basepath/test/test_lib
basepath/test/run.py

I call test/run.py from virtualenv

basepath$ python test/run.py

run.py

import pytest
pytest.main('test/test_lib -v --cov-report xml --cov lib --cov-config .coveragerc')

I tried to move .coveragerc in different directories i.e. lib/, test/, test/test_lib/ but none of them worked.

I expected to get a coverage file named "xxxcoverage" as set in .coveragerc but I always got the default one .coverage

.coveragerc

[run]
data_file = xxxcoverage
like image 408
Christian Scholz Avatar asked Mar 30 '12 09:03

Christian Scholz


People also ask

Where is Pytest INI located?

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.

What does coverage HTML do?

HTML reporting: coverage html ¶ Coverage.py can annotate your source code to show which lines were executed and which were not. The html command creates an HTML report similar to the report summary, but as an HTML file. Each module name links to the source file decorated to show the status of each line.

What is Pragma no cover?

That exact # pragma: no cover is the hint that the part of code should be ignored by the tool -- see Excluding code from coverage .


1 Answers

Reading the pytest documentation again and again...I found my "mistake":
Here it says:

Note that this plugin controls some options and setting the option in the config file will have no effect. These include specifying source to be measured (source option) and all data file handling (data_file and parallel options).

So my test was useless because the data_file option in .coveragerc has no effect.

I tested with the omit option and it worked!

.coveragerc has to be placed in the basepath as described above (and expected)

like image 52
Christian Scholz Avatar answered Sep 27 '22 19:09

Christian Scholz