Skip to content

Commit fca891d

Browse files
authored
Merge pull request #20 from viperior/feature/code-coverage
Code Coverage Analysis
2 parents 460c8b3 + 32c8e71 commit fca891d

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

.github/workflows/python-app.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ jobs:
3232
pytest -v -x -n auto
3333
- name: Test with pytest
3434
run: |
35-
pytest -v
35+
python -m coverage run -m pytest -v
36+
coverage report -m --fail-under 100

CHANGELOG.md

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

3+
## [0.7.0](https://github.com/viperior/python-project-template/tree/v0.7.0) (2022-02-25)
4+
5+
### Improvements
6+
7+
* Measure code coverage using `coverage` and require 100% code coverage to pass PR checks (closes [#9][i9])
8+
9+
### Testing
10+
11+
* Improve the design of the `test_flip_coins_function` to use parametrized test input data and run multiple times with a range of coin count inputs
12+
* Exclude pylint success/failure reporting from code coverage measurement
13+
14+
[i9]: https://github.com/viperior/python-project-template/issues/9
15+
316
## [0.6.0](https://github.com/viperior/python-project-template/tree/v0.6.0) (2022-02-25)
417

518
### Improvements

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
coverage==6.3.2
12
pylint==2.12.2
23
pytest==7.0.1
34
pytest-xdist==2.5.0

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ astroid==2.9.0
88
# via pylint
99
attrs==21.2.0
1010
# via pytest
11+
coverage==6.3.2
12+
# via -r requirements.in
1113
execnet==1.9.0
1214
# via pytest-xdist
1315
iniconfig==1.1.1

tests/test_flip_coins_function.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
import logging
44

5+
import pytest
6+
57
from games_of_chance.flip_coins import flip_coins
68

79

8-
def test_foo_function() -> None:
10+
@pytest.mark.parametrize("coin_count", list(range(11)) + list(range(10, 200, 10)) + [1, 2] * 30)
11+
def test_foo_function(coin_count: int) -> None:
912
"""Example test case
1013
14+
Parameters:
15+
coin_count (int): The number of coins to flip
16+
1117
Returns:
1218
None
1319
"""
14-
coin_flip_result = flip_coins(coins_to_flip=10, chosen_side="heads")
15-
logging.debug("coin_flip_result = %s", coin_flip_result)
20+
try:
21+
coin_flip_result = flip_coins(coins_to_flip=coin_count, chosen_side="heads")
22+
logging.debug("coin_flip_result = %s", coin_flip_result)
1623

17-
assert coin_flip_result["result"] in ["won", "lost", "tie"]
24+
assert coin_flip_result["result"] in ["won", "lost", "tie"]
25+
except AssertionError as error:
26+
# Validate that trying to flip 0 coins causes an error
27+
assert isinstance(error, AssertionError) and coin_count == 0

tests/test_python_code_quality.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def test_python_code_quality() -> None:
1717
pylint_error_free_search_phrase = "Your code has been rated at 10.00/10"
1818
pylint_errors_detected = pylint_error_free_search_phrase not in standard_output_data
1919

20-
if pylint_errors_detected:
20+
if pylint_errors_detected: # pragma: no cover
2121
logging.error("Pylint errors detected:\n%s", standard_output_data)
22+
else: # pragma: no cover
23+
logging.debug("Pylint success output:\n%s", standard_output_data)
2224

2325
assert pylint_error_free_search_phrase in standard_output_data

0 commit comments

Comments
 (0)