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
3
votes
2 answers

How to install python's coverage module and use it from commandline in Windows

I want o learn how to use python's coverage.py module to inspect the coverage pattern of my code. I tried reading about the tool from various sources and finally installed it on my windows 7 machine using 'pip' utility. After installation, the…
VaidAbhishek
  • 5,895
  • 7
  • 43
  • 59
2
votes
1 answer

Getting Python's coverage.py to gather coverage for the module that imports it?

I've been toying around with coverage.py, but can't seem to get it to gather coverage for the __main__ module. I'm on Windows, and like to hack up scripts using IDLE. The edit-hit-F5 cycle is really convenient, fast, and fun. Unfortunately, it…
Richard Levasseur
  • 14,562
  • 6
  • 50
  • 63
2
votes
2 answers

Given an object, how to get a list of bound methods which are called during runtime

The question comes from this scenario: We've built a framework to test northbound apis of our project, based on pytest. And now we want to have a coverage report about how many apis are tested(basically, are called) by running the test scripts we…
Li Feng
  • 931
  • 6
  • 14
2
votes
1 answer

Coverage.py/Cython - Unable to trace into Cython library in complex project with unittest

I have a project that has a model and other components each in a Cython library. I've created unittests and can run those fine with coverage but I only get coverage information for the test code itself (not the libraries the test code is calling). …
DaveH
  • 153
  • 1
  • 9
2
votes
0 answers

Pycharm - coverage in mako templates

I've got tests to cover 100% of my Python code. Beside it my code fails on TypeError in mako template. Is it any way to make pycharm's coverage show code coverage in templates too?
Djent
  • 2,877
  • 10
  • 41
  • 66
2
votes
2 answers

Integrating command-line generated python .coverage files with PyDev

My build environment is configured to compile, run and create coverage file at the command line (using Ned Batchelder coverage.py tool). I'm using Eclipse with PyDev as my editor, but for practical reasons, it's not possible/convenient for me to…
Kena
  • 6,891
  • 5
  • 35
  • 46
2
votes
1 answer

Exclude unit tests from coverage in python

I am new to using coverage.py. I used coverage run unit_tests.py which ran my tests. Then I used coverage report which generated the following coverage summary: Name Stmts Miss Cover -------------------------------- cardnames 28 …
Pranjal Mittal
  • 10,772
  • 18
  • 74
  • 99
2
votes
1 answer

code coverage in python using coverage.py

I am trying to understand running coverage for python scripts. I am not able to understand a scenario where i try to run coverage for a simple script which has an infinite loop: #!/usr/bin/python print "The only statement!!!" while True: …
Vijay
  • 155
  • 2
  • 12
2
votes
1 answer

How to get 100% code coverage in Python?

learning.py def multiply(a, b): return a * b def addition(a, b): return a + b test_learning.py import unittest from learning import * class Test(unittest.TestCase): def test_multiply(self): self.assertEqual( multiply(3,4),…
030
  • 10,842
  • 12
  • 78
  • 123
2
votes
1 answer

Generate html report from .coverage file

I'm looking for a way to combine multiple .coverage files and then generate an html report. Currently I'm generating coverage just from one source with the following command and it works fine: nosetests --with-coverage --cover-erase --cover-html…
hithwen
  • 2,154
  • 28
  • 46
2
votes
1 answer

Can't get Coverage to work in PyDev, "File has no statistics"

I can't get Coverage to work with PyDev. Every file I run shows up with: "File has no statistics." I'm following the instructions by checking 'Enable code coverage for new launches', and dragging the folder to analyze over to the Code Coverage…
Def_Os
  • 5,301
  • 5
  • 34
  • 63
1
vote
1 answer

Python doesn't see submodules when running under coverage and nose

I get an import error when I use coverage.py to run a suite of tests where nose is the underlying test runner. The tests run fine if I just run under Python instead. coverage run…
Lorin Hochstein
  • 57,372
  • 31
  • 105
  • 141
1
vote
0 answers

Python tests coverage report by module

I'm using Coverage to measure the code coverage of my tests, which outputs XML / HTML coverage statistics by file. Is there a way to output the results by python module instead? For example: - module a - 70% - module a.b - 80% - module a.c -…
Tzach
  • 12,889
  • 11
  • 68
  • 115
1
vote
1 answer

How to activate Nose coverage within code in Python 3.5

I have a TestMain.py that inits and runs the Nose tests and I am trying to enable code coverage within it. The tests are currently loaded as follow: if __name__ == '__main__': # Some initialization code here, so command-line cannot be used #…
olivierr91
  • 1,243
  • 3
  • 13
  • 29
1
vote
0 answers

Python unittest coverage branch miss on context __exit__

I've had a number of times where I've done the following: # code m. with open(somefile, modes) as data_interface: .. ... n. ... And then when trying to provide test coverage using python's coverage module it complains about missing a…