Skip to content

Commit d59ba50

Browse files
add pytest-cov to template (#288)
1 parent 918e5b3 commit d59ba50

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1717

1818
## [Unreleased]
1919

20+
### Added
21+
22+
- Added `pytest-cov` as dev dependency.
23+
- Added `branch=True` to coverage configuration.
24+
25+
### Changed
26+
27+
- Adjusted default `pytest` command line arguments to include `pytest-cov` flags, with the default not printing the report to the terminal.
28+
- Changed `just py test` command to erase coverage before each run and to get rid of calling `coverage` directly in favor of `pytest-cov`.
29+
- Always upload coverage html report in CI tests instead of just on failure.
30+
2031
## [2024.45]
2132

2233
### Changed

src/django_twc_project/.github/workflows/test.yml.jinja

+1-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ jobs:
125125
# https://hynek.me/articles/ditch-codecov-python/
126126
- name: Run tests
127127
run: |
128-
time coverage run -m pytest --durations 10 --reverse -p no:randomly -n auto --dist loadfile
128+
time python -m pytest --durations 10 --reverse -p no:randomly -n auto --dist loadfile --cov={{ module_name }} --cov-report= --cov-config=pyproject.toml
129129
python -m coverage html --skip-covered --skip-empty
130130
python -m coverage report | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY
131131
# python -m coverage report --fail-under=100
@@ -135,7 +135,6 @@ jobs:
135135
with:
136136
name: {% raw %}coverage-report-${{ github.run_id }}{% endraw %}
137137
path: htmlcov
138-
if: {% raw %}${{ failure() }}{% endraw %}
139138

140139
types:
141140
runs-on: ubuntu-latest

src/django_twc_project/.just/python.just.jinja

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ lock *ARGS:
4242
# Run tests using pytest within the 'app' container, with optional arguments
4343
[no-cd]
4444
test *ARGS:
45+
@just docker command python -m coverage erase
4546
{%- if include_vite %}
46-
@just docker run app "-e DJANGO_VITE_DEV_SERVER_HOST=node" coverage run -m pytest {% raw %}{{ ARGS }}{% endraw %}
47+
@just docker run app "-e DJANGO_VITE_DEV_SERVER_HOST=node" python -m pytest {% raw %}{{ ARGS }}{% endraw %}
4748
{%- else %}
48-
@just docker command coverage run -m pytest {% raw %}{{ ARGS }}{% endraw %}
49+
@just docker command python -m pytest {% raw %}{{ ARGS }}{% endraw %}
4950
{%- endif %}
5051

5152
# Run tests with Playwright debug mode enabled, in the 'app' container, with optional arguments

src/django_twc_project/pyproject.toml.jinja

+3-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ dev = [
7171
"playwright=={{ playwright_version }}",
7272
"pre-commit",
7373
"pytest",
74+
"pytest-cov",
7475
"pytest-django",
7576
"pytest-is-running",
7677
"pytest-playwright",
@@ -122,6 +123,7 @@ exclude_lines = [
122123
]
123124

124125
[tool.coverage.run]
126+
branch = true
125127
omit = [
126128
"*/node_modules/*",
127129
"{{ module_name }}/*/migrations/*",
@@ -135,7 +137,6 @@ omit = [
135137
"requirements.txt"
136138
]
137139
plugins = ["django_coverage_plugin"]
138-
source = ["{{ module_name }}"]
139140

140141
[tool.django-stubs]
141142
django_settings_module = "{{ module_name }}.settings"
@@ -203,7 +204,7 @@ ignore_missing_model_attributes = true
203204

204205
[tool.pytest.ini_options]
205206
DJANGO_SETTINGS_MODULE = "{{ module_name }}.settings"
206-
addopts = "--reuse-db -n auto --dist loadfile"
207+
addopts = "--reuse-db -n auto --dist loadfile --cov={{ module_name }} --cov-report= --cov-config=pyproject.toml"
207208
norecursedirs = ".* bin build dist *.egg htmlcov logs node_modules static templates venv"
208209
python_files = "tests.py test_*.py *_tests.py"
209210

0 commit comments

Comments
 (0)