Questions tagged [python-coverage]

Coverage.py is a tool for measuring code coverage of Python programs.

Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not.

Coverage measurement is typically used to gauge the effectiveness of tests. It can show which parts of your code are being exercised by tests, and which are not.

See https://coverage.readthedocs.io/

54 questions
6
votes
1 answer

Python unittest branch coverage seems to miss executed generator in zip

I don't quite understand what Python's branch coverage stats are trying to tell me. Given code of the form def f(a, b): c = (i for i in a) d = (j for j in b) # Line of interest return dict(zip(c, d)) print(f(['a', 'b'], [1, 2])) which…
Paul Weaver
  • 284
  • 5
  • 9
6
votes
1 answer

Is it possible to make a code coverage assertion in Python?

When I am writing tests or debugging code I would like to be able to add a line of Python that will notify me if that line is never executed. Is this possible? For example, I want to be able to write code such as: def f(x): if x==0: …
Peter de Rivaz
  • 33,126
  • 4
  • 46
  • 75
6
votes
2 answers

How can I ensure good test-coverage of my big Python proejct

I have a very large python project with a very large test suite. Recently we have decided to quantify the quality of our test-coverage. I'm looking for a tool to automate the test coverage report generation. Ideally I'd like to have attractive,…
Salim Fadhley
  • 22,020
  • 23
  • 75
  • 102
6
votes
1 answer

why is python coverage saying lines were missed?

I'm trying to use coverage with Django, but I seem to be getting incorrect results. My app is named "stats" and I have this test: class ListSchoolsTest(TestCase): def test_initial_list(self): self.client.login(username='skeezy',…
Chris Curvey
  • 9,738
  • 10
  • 48
  • 70
5
votes
2 answers

When would my Python test suite file coverage not be 100%?

We are using Hudson and coverage.py to report the code coverage of our test suite. Hudson breaks down coverage into: packages files classes lines conditionals Coverage.py only reports coverage on files executed/imported during the tests, and so it…
Pete
  • 2,503
  • 4
  • 21
  • 20
5
votes
1 answer

Python unittest: how to satisfy nose coverage for importing packages

For a given python file that has the following lines at the top: import traceback import datetime from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType from django.db import models from…
Duncan
  • 2,550
  • 2
  • 17
  • 18
4
votes
2 answers

NoseTest: running with coverage from Python script

I want to run NoseTest from a Python script. But I want not only run it, but also measure test coverage. Just now I have the following code: import os import sys import…
Felix
  • 3,351
  • 6
  • 40
  • 68
4
votes
2 answers

Python coverage with unittesting

I've written tests for my python code and want to check how much % is covered with tests, so I decided to use python coverage. But I have a problem launching it. I launch my tests with this bash command: export PYTHONPATH=. && python…
4
votes
6 answers

how to know if my Python tests are running in coverage mode?

I am running Ned Batchelder's coverage module on continuous integration using Travis CI but I want to run only integration tests and skip functional ones because they take too long and coverage measurement is not affected by them. I created a…
hvelarde
  • 2,875
  • 14
  • 34
4
votes
1 answer

Can python coverage display results hierarchically?

I use the Python code coverage tool to monitor and measure our testing coverage. I'm now publishing the results internally, using coverage's excellent html report generation. I'd like to change the reports generated from a flat report of all…
dbn
  • 13,144
  • 3
  • 60
  • 86
4
votes
1 answer

Python code coverage

coverage 3.4 Nose 1.1.2 Python 2.7.1 I have a python project structure like the below root src #source directory company division pkg1 module1 module2 pkg2 …
Kannan Ekanath
  • 16,759
  • 22
  • 75
  • 101
3
votes
3 answers

Merge branch coverage files python

I have a multiprocessing application in python. And I am trying to get the coverage report after running my tests. I am trying to merge coverage reports but I am not able to do in a single shot. Following is the issue I am facing. My two tests have…
3
votes
1 answer

Django coverage test for URLs 0%, why?

Using Django Nose. I have tests for my URL's but coverage is still giving me 0% for URLs, why? python manage.py test profiles This is my coverage: Name Stmts Miss Cover …
Prometheus
  • 32,405
  • 54
  • 166
  • 302
3
votes
1 answer

Hudson build failed using Python & Coverage

I completed this tutorial from Joe Heck to set up Hudson for Python. Everything worked perfectly except the Coverage section. My build failed with this output: [workspace] $ /bin/sh -xe /tmp/hudson6222564272447222496.sh + coverage run tests/run.py…
3
votes
1 answer

How calculate the global coverage?

I am using tox to test my python egg. And I want to know the coverage. But the problem is that the tests are executing with python 2 (2.6 and 2.7) and python 3 (3.3) and some lines should be executed in python 2 and other in python 3, but this look…
Goin
  • 3,856
  • 26
  • 44