coverage module

The most important thing in the coverage module is the coverage.Coverage class, described in The Coverage class, but there are a few other things also.

coverage.version_info

A tuple of five elements, similar to sys.version_info: major, minor, micro, releaselevel, and serial. All values except releaselevel are integers; the release level is 'alpha', 'beta', 'candidate', or 'final'. Unlike sys.version_info, the elements are not available by name.

coverage.__version__

A string with the version of coverage.py, for example, "5.0b2".

exception coverage.CoverageException(*args, slug=None)

The base class of all exceptions raised by Coverage.py.

Parameters:
  • args (Any)

  • slug (str | None)

Return type:

None

Starting coverage.py automatically

This function is used to start coverage measurement automatically when Python starts. See Managing processes for details.

coverage.process_startup(*, force=False, slug='default')

Call this at Python start-up to perhaps measure coverage.

Coverage is started if one of these environment variables is defined:

  • COVERAGE_PROCESS_START: the config file to use.

  • COVERAGE_PROCESS_CONFIG: the config data to use, a string produced by CoverageConfig.serialize, prefixed by “:data:”.

If one of these is defined, it’s used to get the coverage configuration, and coverage is started.

For details, see https://coverage.readthedocs.io/en/latest/subprocess.html.

Returns the Coverage instance that was started, or None if it was not started by this call.

Parameters:
  • force (bool)

  • slug (str)

Return type:

Coverage | None