Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pytest-cov to template #288

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ 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`.
- Always upload coverage html report in CI tests instead of just on failure.

## [2024.45]

### Changed
Expand Down
3 changes: 1 addition & 2 deletions src/django_twc_project/.github/workflows/test.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/django_twc_project/.just/python.just.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/django_twc_project/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dev = [
"playwright=={{ playwright_version }}",
"pre-commit",
"pytest",
"pytest-cov",
"pytest-django",
"pytest-is-running",
"pytest-playwright",
Expand Down Expand Up @@ -122,6 +123,7 @@ exclude_lines = [
]

[tool.coverage.run]
branch = true
omit = [
"*/node_modules/*",
"{{ module_name }}/*/migrations/*",
Expand All @@ -135,7 +137,6 @@ omit = [
"requirements.txt"
]
plugins = ["django_coverage_plugin"]
source = ["{{ module_name }}"]

[tool.django-stubs]
django_settings_module = "{{ module_name }}.settings"
Expand Down Expand Up @@ -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"

Expand Down