546 questions
142
votes
6
answers
90k
views
Is it possible exclude test directories from coverage.py reports?
I'm kind of a rookie with python unit testing, and particularly coverage.py. Is it desirable to have coverage reports include the coverage of your actual test files?
Here's a screenshot of my HTML ...
83
votes
15
answers
89k
views
python coverage output: Coverage.py warning: No data was collected. (no-data-collected)
I am trying to find the coverage using the coverage module for a django project but gets
Coverage.py warning: No data was collected. (no-data-collected)
My project folder has src and tests folders.
...
80
votes
5
answers
141k
views
How to properly use coverage.py in Python?
I've just started using Coverage.py module and so decided to make a simple test to check how it works.
Sample.py
def sum(num1, num2):
return num1 + num2
def sum_only_positive(num1, num2):
if ...
74
votes
4
answers
38k
views
How do I make coverage include not tested files?
I have just started writing some unit tests for a python project I have using unittest and coverage. I'm only currently testing a small proportion, but I am trying to work out the code coverage
I run ...
72
votes
5
answers
57k
views
coverage.py: exclude files
How do I exclude entire files from coverage.py reports?
According to the documentation you can exclude code by matching lines. I want to exclude entire files, so that the reports don't include 3rd ...
68
votes
4
answers
29k
views
preventing python coverage from including virtual environment site packages
I am new to coverage and ran into a strange problem. My coverage is taking my virtual environment site packages into account.
Here is the output of the coverage run:
coverage run test.py
................
67
votes
3
answers
194k
views
How to get coverage reporting when testing a pytest plugin?
Context
I am updating an inherited repository which has poor test coverage. The repo itself is a pytest plugin. I've changed the repo to use tox along with pytest-cov, and converted the "raw"...
64
votes
2
answers
21k
views
How to Fix Python Nose: Coverage not available: unable to import coverage module
I can't seem to get code coverage with Nose to work, despite having the plugin installed.
Any ideas on how to fix this?
12:15:25 ~/sandbox/ec$ nosetests --plugins
Plugin xunit
Plugin deprecated
...
59
votes
4
answers
15k
views
Excluding abstractproperties from coverage reports
I have an abstract base class along the lines of:
class MyAbstractClass(object):
__metaclass__ = ABCMeta
@abstractproperty
def myproperty(self): pass
But when I run nosetests (which ...
49
votes
5
answers
35k
views
Using py.test with coverage doesn't include imports
For Jedi we want to generate our test coverage. There is a related question in stackoverflow, but it didn't help.
We're using py.test as a test runner. However, we are unable to add the imports and ...
47
votes
5
answers
37k
views
combine python coverage files?
I'm wondering if it's possible to combine coverage.xml files into 1 file to see global report in HTML output.
I've got my unit/functional tests running as 1 command and integration tests as the ...
38
votes
5
answers
44k
views
py.test gives Coverage.py warning: Module sample.py was never imported
I ran a sample code from this thread.
How to properly use coverage.py in Python?
However, when I executed this command py.test test.py --cov=sample.py
it gave me a warning, therefore, no report was ...
37
votes
1
answer
14k
views
Coverage.py Vs pytest-cov
The documentation of coverage.py says that Many people choose to use the pytest-cov plugin, but for most purposes, it is unnecessary. So I would like to know what is the difference between these two? ...
35
votes
3
answers
11k
views
Python Code Coverage and Multiprocessing
I use coveralls in combination with coverage.py to track python code coverage of my testing scripts. I use the following commands:
coverage run --parallel-mode --source=mysource --omit=*/stuff/idont/...
33
votes
4
answers
24k
views
coverage.py does not cover script if py.test executes it from another directory
I got a python script which takes command line arguments, working with some files.
I'm writing succeeding tests with py.test putting this script through its paces, executing it with subprocess.call.
...
31
votes
6
answers
9k
views
How can I exclude South migrations from coverage reports using coverage.py
I use coverage.py to check the test coverage of my django application. However since I use South for my database migrations, all those files show up with 0% and mess up the overall percentage.
I ...
28
votes
2
answers
16k
views
Making py.test, coverage and tox work together: __init__.py in tests folder?
I'm having a weird problem with tox, py.test, coverage and pytest-cov: when py.test with the --cov option is launched from tox, it seems to require an __init__.py file in the tests folder which is not ...
28
votes
1
answer
22k
views
Exclude a function from coverage
I am using coverage.py to get the test coverage of the code.
Suppose I have two functions with the same name in two different modules
# foo/foo.py
def get_something():
# fetch something
# 10 ...
27
votes
2
answers
4k
views
Finding unused Django code to remove
I've started working on a project with loads of unused legacy code in it. I was wondering if it might be possible to use a tool like coverage in combination with a crawler (like the django-test-utils ...
26
votes
1
answer
3k
views
Why doesn't coverage.py properly measure Django's runserver command?
I should know the answer to this, but I don't: if you try to measure the coverage of a Django project like this:
coverage run manage.py runserver
you get coverage measurement that misses all of your ...
24
votes
3
answers
10k
views
Python nosetests with coverage no longer shows missing lines
I've been using the following command to run tests and evaluate code coverage for a Python project for over a year now.
nosetests -v --with-coverage --cover-package=genhub genhub/*.py
The coverage ...
24
votes
5
answers
9k
views
How do I configure PyCharm's Coverage checker to recognize .coveragerc?
I have a .coveragerc file in the root of my project. It tells coverage.py to omit my project's migrations directories:
[run]
omit = *migrations*
When I run coverage.py at the command line, the config ...
23
votes
5
answers
17k
views
Python coverage - exclude packages
I'm using the python coverage tool to run my unit test. As you can see from the result, it includes all the "site-packages". How can I exclude them from the report? I only want to show the report for ...
23
votes
2
answers
8k
views
Running coverage inside virtualenv
I recently stumbled upon some issue with running coverage measurements within virtual environment. I do not remember similar issues in the past, nor I was able to find solution on the web.
Basically, ...
23
votes
1
answer
28k
views
Python unit test coverage for multiple modules
I searched for a long time and surprisingly found no satisfactory answer.
I have multiple modules/files in my Python project that I wrote unit tests for using unittest. The structure is such that I ...
23
votes
5
answers
16k
views
Coverage badge in Gitlab CI with Python coverage always unknown
I am trying to show a coverage badge for a Python project in a private Gitlab CE installation (v11.8.6), using coverage.py for Python. However, the badge always says unknown.
This is the relevant job ...
22
votes
3
answers
37k
views
WARNING: Failed to generate report: No data to report error in python using pytest module
sample.py
def sum(num1, num2):
return num1 + num2
def sum_only_positive(num1, num2):
if num1 > 0 and num2 > 0:
return num1 + num2
else:
return None
test_sample.py
...
22
votes
3
answers
7k
views
Azure PublishCodeCoverageResults@2 issue with detailed report for coverage
I'm trying to switch PublishCodeCoverageResults from @1 to @2. Because appeared warnig in pipeline
##[warning]New V2 version of task publishing code coverage results is available to all our customers ...
21
votes
2
answers
2k
views
Analyzing coverage of numba-wrapped functions
I've written a python module, much of which is wrapped in @numba.jit decorators for speed. I've also written lots of tests for this module, which I run (on Travis-CI) with py.test. Now, I'm trying ...
20
votes
2
answers
9k
views
How to get combined code coverage over multiple runs of Python script
I've got a python program which is tested by running it several times with different inputs, and comparing the outputs against reference results.
I'd like to get code coverage of all the tests ...
20
votes
3
answers
5k
views
python running coverage on never ending process
I have a multi processed web server with processes that never end, I would like to check my code coverage on the whole project in a live environment (not only from tests).
The problem is, that since ...
20
votes
1
answer
2k
views
Coverage of Cython module using py.test and coverage.py
I want to get coverage information of a Cython module using some (unit) tests written in Python. What I have right now is coverage of the tests themselves, i.e. which lines of the tests are executed ...
19
votes
4
answers
31k
views
How to run coverage.py on a directory?
I have a directory tests that includes a lot of different tests named test_*.
I tried to run coverage run tests but it doesn't work.
How can I run a single command to coverage multiple files in the ...
19
votes
4
answers
7k
views
coverage in parallel for django tests
I am running the following through a Makefile:
NPROCS:=$(shell /usr/bin/nproc)
.PHONY: coverage-app
coverage-app:
coverage erase --rcfile=./.coveragerc-app
coverage run --parallel-mode --...
19
votes
1
answer
13k
views
How do I interpret Python coverage.py branch coverage results?
I'm using coverage.py to measure the code coverage of my tests. I've enabled branch coverage, but I can't quite make sense of the report.
Without branch coverage, I get 100% coverage:
Name ...
18
votes
3
answers
13k
views
PyCharm: Coverage in community edition?
AFAIK the feature "test coverage" is only available in the professional version (code-coverage).
How to see code coverage of my tests with the PyCharm community version?
18
votes
2
answers
5k
views
Flask Testing - why does coverage exclude import statements and decorators?
My tests clearly execute each function, and there are no unused imports either. Yet, according to the coverage report, 62% of the code was never executed in the following file:
Can someone please ...
18
votes
2
answers
1k
views
Coverage: Which test touched this line?
Up to now the coverage in Python binary: A line was executed or not.
Is there a way to get per python code line a lists of tests which execute this line?
I read the coverage docs, but could not find ...
17
votes
3
answers
5k
views
Tox 0% coverage
I have a python project where I use:
pipenv
tox
pytest
and many more.
Basically, I want to add tox to my gitlab pipelines. And almost everything seems to work, calling mypy, flake8 or black from tox ...
17
votes
4
answers
9k
views
How to omit (remove) virtual environment (venv) from python coverage unit testing?
https://coverage.readthedocs.io/en/coverage-4.5.1a/source.html#source
My coverage is also including “venv” folder and I would like to exclude it
no matter what I do even with --include or omit ...
17
votes
1
answer
4k
views
How to get coverage data from a django app when running in gunicorn
How do I get code coverage out of a Django project's view code (and code called by view code)?
coverage gunicorn <params> does not show any lines being hit.
16
votes
2
answers
2k
views
Get rid of absolute paths from coverage.xml report generated by coverage.py
Is there a way to get relative paths to resulted coverage.xml (or strip off prefix) using coverage.py?
15
votes
3
answers
21k
views
How to exclude a file from coverage.py?
I use nosetest's coverage.py plugin. Is it somehow possible to exclude entire files or folders from the coverage report? My use case is having an external library in my project folder that obviously ...
14
votes
3
answers
10k
views
Pycharm/IntelliJ shows 0% coverage for pytest even though coverage was generated
I have a Python project and a tests task, set up to run pytest from the project's working directory.
Doing Run 'tests' with coverage from the Run menu successfully runs the tests, and the console ...
14
votes
2
answers
17k
views
How to setup a different html output directory for coverage report with pytest?
Using coverage with pytests is a very useful tool.
Html reporting allows for nice output, however through command line, can't find an option to modify the default output directory (htmlcov)
example ...
13
votes
3
answers
31k
views
Using omit flag in Python coverage.py API
I'm using the python coverage.py to create a very basic test suite with coverage. Currently everything works great. However, my coverage report includes all the /usr/local/lib libraries that are ...