banner ad

Measuring code coverage for Python programs Tool

| January 20, 2013 | 0 Comments
0 Flares 0 Flares × 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.
The latest version is 3.6, released 5 January 2013. It is supported on Python versions 2.3 through 3.3, and PyPy 1.8.

Getting started is easy:

  1. Install from the coverage page on the Python Package Index, or by using “pip install coverage”. For a few more details, see Installation.
  2. Use coverage run to run your program and gather data:

    $ coverage run arg1 arg2
    blah blah ..your program's output.. blah blah

  3. Use coverage report to report on the results:

    $ coverage report -m
    Name                      Stmts   Miss  Cover   Missing
    my_program                   20      4    80%   33-35, 39
    my_other_module              56      6    89%   17-23
    TOTAL                        76     10    87%

  4. For a nicer presentation, use coverage html to get annotated HTML listings detailing missed lines:

    $ coverage html 

Download PDF
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Reddit 0 StumbleUpon 0 0 Flares ×

Category: Uncategorized

About the Author ()

My name is John Link.I am 26 years old. My major is Computer science and technology. I am a junior programmer with Python.

Leave a Reply

Your email address will not be published. Required fields are marked *

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Reddit 0 StumbleUpon 0 0 Flares ×