From cce3e56915beb24bc3a23ecf02efef4c505ee79a Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 6 Aug 2024 11:02:26 -0500 Subject: [PATCH 1/3] add `pytest-cov` to template --- src/django_twc_project/.just/python.just.jinja | 5 +++-- src/django_twc_project/pyproject.toml.jinja | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/django_twc_project/.just/python.just.jinja b/src/django_twc_project/.just/python.just.jinja index 5eb80a84..64e65b1a 100644 --- a/src/django_twc_project/.just/python.just.jinja +++ b/src/django_twc_project/.just/python.just.jinja @@ -42,10 +42,11 @@ lock *ARGS: # Run tests using pytest within the 'app' container, with optional arguments [no-cd] test *ARGS: + @just docker command python -m coverage erase {%- if include_vite %} - @just docker run app "-e DJANGO_VITE_DEV_SERVER_HOST=node" coverage run -m pytest {% raw %}{{ ARGS }}{% endraw %} + @just docker run app "-e DJANGO_VITE_DEV_SERVER_HOST=node" python -m pytest {% raw %}{{ ARGS }}{% endraw %} {%- else %} - @just docker command coverage run -m pytest {% raw %}{{ ARGS }}{% endraw %} + @just docker command python -m pytest {% raw %}{{ ARGS }}{% endraw %} {%- endif %} # Run tests with Playwright debug mode enabled, in the 'app' container, with optional arguments diff --git a/src/django_twc_project/pyproject.toml.jinja b/src/django_twc_project/pyproject.toml.jinja index d18c88c4..cb1da8bc 100644 --- a/src/django_twc_project/pyproject.toml.jinja +++ b/src/django_twc_project/pyproject.toml.jinja @@ -71,6 +71,7 @@ dev = [ "playwright=={{ playwright_version }}", "pre-commit", "pytest", + "pytest-cov", "pytest-django", "pytest-is-running", "pytest-playwright", @@ -122,6 +123,7 @@ exclude_lines = [ ] [tool.coverage.run] +branch = true omit = [ "*/node_modules/*", "{{ module_name }}/*/migrations/*", @@ -135,7 +137,6 @@ omit = [ "requirements.txt" ] plugins = ["django_coverage_plugin"] -source = ["{{ module_name }}"] [tool.django-stubs] django_settings_module = "{{ module_name }}.settings" @@ -203,7 +204,7 @@ ignore_missing_model_attributes = true [tool.pytest.ini_options] DJANGO_SETTINGS_MODULE = "{{ module_name }}.settings" -addopts = "--reuse-db -n auto --dist loadfile" +addopts = "--reuse-db -n auto --dist loadfile --cov={{ module_name }} --cov-report= --cov-config=pyproject.toml" norecursedirs = ".* bin build dist *.egg htmlcov logs node_modules static templates venv" python_files = "tests.py test_*.py *_tests.py" From 89b07ddb82928075b6e520f2246fb5e1b42a1356 Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 6 Aug 2024 11:04:33 -0500 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e969f21d..f3075f1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added + +- Added `pytest-cov` as dev dependency. +- Added `branch=True` to coverage configuration. + +### Changed + +- Adjusted default `pytest` command line arguments to include `pytest-cov` flags, with the default not printing the report to the terminal. +- Changed `just py test` command to erase coverage before each run and to get rid of calling `coverage` directly in favor of `pytest-cov`. + ## [2024.45] ### Changed From 0c4ed5e8c859b364b0d659ab9aeb59422b88f7a0 Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 6 Aug 2024 11:07:34 -0500 Subject: [PATCH 3/3] adjust CI coverage call --- CHANGELOG.md | 1 + src/django_twc_project/.github/workflows/test.yml.jinja | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3075f1e..aa623670 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Adjusted default `pytest` command line arguments to include `pytest-cov` flags, with the default not printing the report to the terminal. - Changed `just py test` command to erase coverage before each run and to get rid of calling `coverage` directly in favor of `pytest-cov`. +- Always upload coverage html report in CI tests instead of just on failure. ## [2024.45] diff --git a/src/django_twc_project/.github/workflows/test.yml.jinja b/src/django_twc_project/.github/workflows/test.yml.jinja index 3440021c..edd9d998 100644 --- a/src/django_twc_project/.github/workflows/test.yml.jinja +++ b/src/django_twc_project/.github/workflows/test.yml.jinja @@ -125,7 +125,7 @@ jobs: # https://hynek.me/articles/ditch-codecov-python/ - name: Run tests run: | - time coverage run -m pytest --durations 10 --reverse -p no:randomly -n auto --dist loadfile + time python -m pytest --durations 10 --reverse -p no:randomly -n auto --dist loadfile --cov={{ module_name }} --cov-report= --cov-config=pyproject.toml python -m coverage html --skip-covered --skip-empty python -m coverage report | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY # python -m coverage report --fail-under=100 @@ -135,7 +135,6 @@ jobs: with: name: {% raw %}coverage-report-${{ github.run_id }}{% endraw %} path: htmlcov - if: {% raw %}${{ failure() }}{% endraw %} types: runs-on: ubuntu-latest