Skip to content

Commit

Permalink
build: omit certain lines/files from code coverage #313
Browse files Browse the repository at this point in the history
- This commit adds a dev dependency which is used to conditionally exclude lines of code from test coverage reporting. There is a particular line of code in `models.py` which is only used in Python 3.7+, so for 3.6, this line can be excluded from coverage checks
  • Loading branch information
MRichards99 committed Feb 16, 2022
1 parent d62e45a commit 0587a66
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 35 deletions.
2 changes: 1 addition & 1 deletion datagateway_api/src/search_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _is_panosc_entity_field_of_type_list(entity_field):
hasattr(entity_field_outer_type, "_name")
and entity_field_outer_type._name == "List"
):
is_list = True
is_list = True # pragma: py-37-code
# The `_name` `outer_type_` attribute was introduced in Python 3.7 so to check
# whether the field is of type list in Python 3.6, we are checking the type of its
# default value. We must ensure that any new list fields that get added in future
Expand Down
79 changes: 45 additions & 34 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ coverage = {extras = ["toml"], version = "^5.3"}
pytest-cov = "^2.10.1"
pytest-icdiff = "^0.5"
python-semantic-release = "^7.19.2"
coverage-conditional-plugin = "^0.5.0"

[tool.poetry.scripts]

Expand All @@ -69,6 +70,16 @@ source = ["datagateway_api"]
[tool.coverage.run]
branch = true
source = ["datagateway_api"]
plugins = ["coverage_conditional_plugin"]
omit = [
"*api_start_utils.py",
"*logger_setup.py",
"*main.py",
"*wsgi.py",
]

[tool.coverage.coverage_conditional_plugin.rules]
py-37-code = "sys_version_info > (3, 6)"

[tool.coverage.report]
show_missing = true

0 comments on commit 0587a66

Please sign in to comment.