summaryrefslogtreecommitdiff
path: root/doc/api.rst
blob: 855e3ec6f83b1570fe1aecab298e6cb2391848fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
.. Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
.. For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt

.. _api:

===============
Coverage.py API
===============

There are a few different ways to use coverage.py programmatically.

The API to coverage.py is in a module called `coverage`.
Most of the interface is in the :class:`coverage.Coverage` class.  Methods on
the Coverage object correspond roughly to operations available in the command
line interface. For example, a simple use would be::

    import coverage

    cov = coverage.Coverage()
    cov.start()

    # .. call your code ..

    cov.stop()
    cov.save()

    cov.html_report()

Coverage.py supports plugins that can change its behavior, to collect
information from non-Python files, or to perform complex configuration.  See
:ref:`api_plugin` for details.

If you want to access the data that coverage.py has collected, the
:class:`coverage.CoverageData` class provides an API to read coverage.py data
files.

.. note::

    Only the documented portions of the API are supported. Other names you may
    find in modules or objects can change their behavior at any time. Please
    limit yourself to documented methods to avoid problems.

For more intensive data use, you might want to access the coverage.py database
file directly.  The schema is subject to change, so this is for advanced uses
only.  :ref:`dbschema` explains more.

.. toctree::
    :maxdepth: 1

    api_coverage
    api_module
    api_plugin
    api_coveragedata
    dbschema