Skip to content

Commit 1d49b37

Browse files
committed
Adding code coverage reporting.
1 parent b6ce56a commit 1d49b37

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Changelog
22

3+
* Added code coverage reporting to `test` target for _invoke_.
34
* Updated `as_tuple` for complex objects as well as the `as_tuples` parameter for `select`
45
and `get_all` functions to work with strings or 2-tuples. The use of a dictionary
56
was removed as dictionaries don't define an order.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ requests
66
Deprecated
77
pytest
88
pytest-asyncio
9+
pytest-cov
910
responses
1011
python-dotenv
1112
invoke

tasks.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ def lint(c, scope='all'):
5656
'scope': "Which tests to run, e.g. 'tests.model'"
5757
"Default: 'tests'",
5858
'python': ("Whether to run tests within a docker container and which"
59-
"Python version to use - 3.7 or 3.11. Default: None")
59+
"Python version to use - 3.7 or 3.11. Default: None"),
60+
'coverage': "Whether to include coverage analysis.",
6061
})
61-
def test(c, scope='tests', python=None):
62+
def test(c, scope='tests', python=None, coverage=False):
6263
"""Run test."""
6364

65+
cov_option = '--cov=c8y_api' if coverage else ''
66+
6467
docker_name = None
6568
if python == '3.7':
6669
docker_name = 'buster37'
@@ -74,11 +77,14 @@ def test(c, scope='tests', python=None):
7477
cmd_run = (f'docker run --rm -it -v $(pwd):/code {docker_name} '
7578
'bash -c "cd /code '
7679
'&& export PYTHONPATH="/code:${PYTHONPATH}" '
77-
f'&& pytest -W ignore::DeprecationWarning {scope}"')
80+
f'&& pytest -W ignore::DeprecationWarning {cov_option} {scope}"')
7881
print(f"Executing '{cmd_run}' ...")
7982
c.run(cmd_run, pty=True)
8083
else:
81-
c.run(f"pytest -W ignore::DeprecationWarning {scope}")
84+
c.run(f"pytest -W ignore::DeprecationWarning {cov_option} {scope}")
85+
86+
if coverage:
87+
c.run(f"coverage html -d coverage --data-file .coverage")
8288

8389

8490
@task

0 commit comments

Comments
 (0)