The Sphinx extension sphinx_reports
offers a set of directives to integrate reports and summaries into the
documentation generated by Sphinx.
Supported format reports are:
- β
π§ Unit Test summaries (by pytest)
- β
Summary page (displaying
unittest.xml
) - π§ Show logging, output and error messages.
- β
Summary page (displaying
- π§ Code coverage (by Coverage.py)
- β
Summary page (displaying
coverage.json
) - π§ Individual Sphinx documents per package/module
- π§ Highlighted source code with syntax highlighting and coverage highlighting
- β
Summary page (displaying
- π§ Documentation coverage
- β Summary page (displaying data from """docstr_coverage""")
- β Additionally support interrogate as data source.
- π§ Individual Sphinx documents per package/module
- π§ Highlighted source code with syntax highlighting and coverage highlighting
- π§ Package Dependencies
- π§ Summary page (displaying
requirements.txt
)
- π§ Summary page (displaying
This README demonstrates a quick and minimal configuration for the Sphinx extension and it's provided directives. See the sphinx-reports documentation for more details.
At first, add the extension name to the list of extensions in conf.py
, so the extension is loaded by Sphinx.
# Sphinx extensions
extensions = [
# ...
"sphinx_reports",
]
Each report directive might require an individual configuration, therefore see the next sections for details.
The Unittests Report collects the success or failure of unittests. The results are typically stored in an XML file, which can be read by sphinx-reports. After reading the structure of testsuites and testcases, the report can be visualized. The user
This is a quick and minimal configuration for the unittest summary directives. See the unittest documentation for more details.
Quick Configuration - Step-by-Step
-
Configure one or more coverage analysis reports in
conf.py
by adding a new 'section' defining some configuration variables. Each unittest report is identified by an ID, which is later referred to by the report directive. Here, the ID is calledsrc
(dictionary key). Each unittest report needs 1 configuration entry:xml_report
- The unittest report as XML file as generated by pytest.
report_unittest_testsuites = { "src": { "xml_report": "../report/unit/unittest.xml" } }
-
Add the
unittest-summary
directive into your Restructured Text (ReST) document.reportid
- The ID used inconf.py
to describe a report.
.. report:unittest-summary:: :reportid: src
Code Coverage checks if a source code was used during execution. Usually, testcases are run by a testcase execution
framework like pytest, which also offers to instrument the code for code
coverage collection using the pytest-cov
plugin. For Python, coverage collection is usually based on
Coverage.py, which supports statement and branch coverage collection either as
XML or JSON files. sphinx-reports can visualize a code coverage summary from JSON files.
This is a quick and minimal configuration for the code coverage directives. See the code coverage documentation for more details.
Quick Configuration - Step-by-Step
-
Configure one or more coverage analysis reports in
conf.py
by adding a new 'section' defining some configuration variables. Each analysis report is identified by an ID, which is later referred to by the report directive. Here, the ID is calledsrc
(dictionary key). Each analysis report needs 4 configuration entries:name
- Name of the Python package1.json_report
- The code coverage report as JSON file as generated by Coverage.py.fail_below
- An integer value in range 0..100, for when a code coverage is considered FAILED.levels
- A predefined color pallet name or a dictionary of coverage limits, their description and CSS style classes.
# ============================================================================== # Sphinx-reports - CodeCov # ============================================================================== report_codecov_packages = { "src": { "name": "myPackage", "json_report": "../report/coverage/coverage.json", "fail_below": 80, "levels": "default" } }
-
Add the
code-coverage
directive into your Restructured Text (ReST) document.reportid
- The ID used inconf.py
to describe a Python package.
.. report:code-coverage:: :reportid: src
Documentation Coverage counts how many publicly accessible members are documented using a Python doc-string. Based on the count of possibly documented public members and the actual number of non-empty doc-strings, a percentage of documentation coverage can be computed.
Documentation coverage is a measure of code quality, which expresses how well documented (completeness or documentation, but not necessarily quality/helpfulness of documentation) source code is. Well documented code helps to use and maintain the existing code base. It also allows for automated documentation generation.
This is a quick and minimal configuration for the documentation coverage directives. See the documentation coverage documentation for more details.
Quick Configuration - Step-by-Step
-
Configure one or more Python packages for documentation coverage analysis in
conf.py
by adding a new 'section' defining some configuration variables. Each package is identified by an ID, which is later referred to by the report directive. Here, the ID is calledsrc
(dictionary key). Each package needs 4 configuration entries:name
- Name of the Python package1.directory
- The directory of the package to analyze.fail_below
- An integer value in range 0..100, for when a documentation coverage is considered FAILED.levels
- A predefined color pallet name or a dictionary of coverage limits, their description and CSS style classes.
# ============================================================================== # Sphinx-reports - DocCov # ============================================================================== report_doccov_packages = { "src": { "name": "myPackage", "directory": "../myPackage", "fail_below": 80, "levels": "default" } }
-
Add the
doc-coverage
directive into your Restructured Text (ReST) document.reportid
- The ID used inconf.py
to describe a Python package.
.. report:doc-coverage:: :reportid: src
π§ In planning phase π§
- Patrick Lehmann (Maintainer)
- and more...
This Python package (source code) is licensed under Apache License 2.0.
The accompanying documentation is licensed under Creative Commons - Attribution-4.0 (CC-BY 4.0).
SPDX-License-Identifier: Apache-2.0