Test coverage reporting¶
Use this plugin to activate coverage report.
To use this plugin, you need to install nose2[coverage_plugin]. e.g.
$ pip install nose2[coverage_plugin]>=0.6.5
Then, you can enable coverage reporting with :
$ nose2 --with-coverage
Or with this lines in unittest.cfg :
[coverage]
always-on = True
You can further specify coverage behaviors with a .coveragerc file, as
specified by Coverage Config.
However, when doing so you should also be aware of
Differences From coverage.
Configuration [coverage]¶
-
always-on¶ - Default
False
- Type
boolean
-
coverage¶ - Default
[]
- Type
list
-
coverage-config¶ - Default
- Type
str
-
coverage-report¶ - Default
[]
- Type
list
Sample configuration¶
The default configuration is equivalent to including the following in a unittest.cfg file.
[coverage]
always-on = False
coverage =
coverage-config =
coverage-report =
Command-line options¶
-
--coveragePATH¶ Measure coverage for filesystem path (multi-allowed)
-
--coverage-reportTYPE¶ Generate selected reports, available types: term, term-missing, annotate, html, xml (multi-allowed)
-
--coverage-configFILE¶ Config file for coverage, default: .coveragerc
-
-CDEFAULT,--with-coverageDEFAULT¶ Turn on coverage reporting
Plugin class reference: Coverage¶
-
class
nose2.plugins.coverage.Coverage(*args, **kwargs)[source]¶ -
afterSummaryReport(event)[source]¶ Reporting data is collected, failure status determined and set. Now print any buffered error output saved from beforeSummaryReport
-
Differences From coverage¶
The coverage tool is the basis for nose2’s coverage reporting. nose2 will
seek to emulate coverage behavior whenever possible, but there are known
cases where this is not feasible.
If you need the exact behaviors of coverage, consider having coverage
invoke nose2.
Otherwise, please be aware of the following known differences:
The
fail_underparameter results in an exit status of 2 forcoverage, but an exit status of 1 fornose2
Compatibility with mp plugin¶
The coverage and mp plugins may be used in conjuction to enable
multiprocess testing with coverage reporting.
Special instructions:
Due to the way the plugin is reloaded in subprocesses, command-line options for the
coverageplugin have no effect. If you need to change anycoverageplugin options, use a configuration file.Do not use the
concurrencyoption within a.coveragercfile ; this interferes with thecoverageplugin, which automatically handles multiprocess coverage reporting.