Skip to content

Commit 8a68d61

Browse files
committed
chore: add test-coverage
1 parent 0ea896b commit 8a68d61

File tree

6 files changed

+165
-4
lines changed

6 files changed

+165
-4
lines changed

.github/workflows/run-unittests.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,26 @@ jobs:
3939
- name: Run unittests
4040
run: |
4141
mkdir -p reports
42-
PYTHONPATH=./src:./tests poetry run pytest ./tests/unit_test --junitxml=reports/report.xml
42+
PYTHONPATH=./src:./tests poetry run pytest \
43+
--cov=src \
44+
--cov-report=xml:reports/coverage.xml \
45+
--junitxml=reports/report.xml \
46+
./tests/unit_test
47+
48+
- name: Upload coverage report
49+
if: matrix.python-version == '3.12'
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: coverage-${{ matrix.python-version }}
53+
path: reports/coverage.xml
54+
55+
- name: Upload to Codecov
56+
if: matrix.python-version == '3.12'
57+
uses: codecov/codecov-action@v4
58+
with:
59+
files: reports/coverage.xml
60+
flags: unittests
61+
fail_ci_if_error: true
4362

4463
- name: Upload JUnit report
4564
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,9 @@ env.make
7575

7676
# Docs
7777
docs/.venv
78+
79+
# Test Coverage
80+
.coverage
81+
82+
# Test Reports
83+
reports/

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@ help:
3232

3333
.PHONY: test
3434
test: ## run test suite
35-
PYTHONPATH=$(SRC):$(TESTS) poetry run pytest $(TESTS)
35+
PYTHONPATH=$(SRC):$(TESTS) poetry run pytest \
36+
$(TESTS)
37+
38+
.PHONY: test-coverage
39+
test-coverage: ## run test suite with coverage and show terminal report
40+
PYTHONPATH=$(SRC):$(TESTS) poetry run pytest \
41+
--cov=$(SRC) \
42+
--cov-report=term-missing \
43+
--cov-report=xml:reports/coverage.xml \
44+
--cov-fail-under=90 \
45+
$(TESTS)
3646

3747
################################################################################
3848
# RELEASE

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
[![Author: David Runemalm](https://img.shields.io/badge/Author-David%20Runemalm-blue)](https://www.davidrunemalm.com)
33
[![Python Versions](https://img.shields.io/pypi/pyversions/py-dependency-injection)](https://pypi.org/project/py-dependency-injection/)
44
[![Master workflow](https://github.com/runemalm/py-dependency-injection/actions/workflows/master.yml/badge.svg?branch=master)](https://github.com/runemalm/py-dependency-injection/actions/workflows/master.yml)
5+
[![Codecov](https://codecov.io/gh/runemalm/py-dependency-injection/branch/master/graph/badge.svg)](https://codecov.io/gh/runemalm/py-dependency-injection)
56
[![PyPI version](https://badge.fury.io/py/py-dependency-injection.svg)](https://pypi.org/project/py-dependency-injection/)
67
![Downloads](https://pepy.tech/badge/py-dependency-injection)
78
![No dependencies](https://img.shields.io/badge/dependencies-none-brightgreen)

poetry.lock

Lines changed: 126 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pre-commit = "*"
4242
pytest = "*"
4343
setuptools = "*"
4444
wheel = "*"
45+
pytest-cov = "^6.2.1"
4546

4647
[build-system]
4748
requires = ["poetry-core>=2.0.0,<3.0.0"]

0 commit comments

Comments
 (0)