Skip to content

Introduce test coverage report #78

@Tql-ws1

Description

@Tql-ws1

This issue extends from the discussion in #72 on introducing test coverage reports.

Currently, I have added configuration related to Coverage.py in the pyproject.toml file and plan to create a coverage/ directory in the root of the code repository to store the test coverage reports as well as any coverage badge that may be needed in the future.

Expected changes to pyproject.toml
diff --git a/pyproject.toml b/pyproject.toml
index 01b930950b..7c647c81fd 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -18,3 +18,38 @@
 profile = "google"
 src_paths = ["src/code"]
 forced_separate = ["typing"]
+
+[tool.coverage.run]
+data_file = "coverage/.coverage"
+branch = true
+source = ["src/code"]
+omit = ["src/code/main.py"]
+command_line = """
+    --module unittest discover \
+    --start-directory src.code \
+    --pattern '*_test.py' \
+    --top-level-directory ./
+"""
+
+[tool.coverage.report]
+show_missing = true
+# Regexes for lines to exclude from consideration
+exclude_also = [
+    # Don't complain about missing debug-only code:
+    "def __repr__",
+    "if self\\.debug",
+
+    # Don't complain if tests don't hit defensive assertion code:
+    "raise AssertionError",
+    "raise NotImplementedError",
+
+    # Don't complain if non-runnable code isn't run:
+    "if 0:",
+    "if __name__ == .__main__.:",
+
+    # Don't complain about abstract methods, they aren't run:
+    "@(abc\\.)?abstractmethod",
+]
+
+[tool.coverage.html]
+directory = "coverage/htmlcov"

To view the line-by-line coverage report on the local machine, users need to clone the repository and install Coverage.py, then run it to generate the report in a format that is convenient for them. If the report is meant to be viewed online by everyone, the only idea I can think of is to use a third-party platform service.

There are ready-to-use actions on the GitHub Marketplace that can update the coverage report and coverage badge during CI runs, but this requires a GitHub token or GitHub Pages.


Originally, I planned to create a dynamic context plugin that would help us better understand whether the responsibility division of functions is reasonable. However, after reading the plugin documentation, I realized it was beyond my capabilities, so I dropped the idea...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions