diff --git a/django/{{ cookiecutter.project_slug }}/.gitlab/ci/test.gitlab-ci.yml b/django/{{ cookiecutter.project_slug }}/.gitlab/ci/test.gitlab-ci.yml index 9e65a14..d2ecf52 100644 --- a/django/{{ cookiecutter.project_slug }}/.gitlab/ci/test.gitlab-ci.yml +++ b/django/{{ cookiecutter.project_slug }}/.gitlab/ci/test.gitlab-ci.yml @@ -11,7 +11,24 @@ django-test: POSTGRES_HOST: "postgres" POSTGRES_PORT: "5432" script: - - uv run manage.py test + - uv run coverage run manage.py test --no-input --keepdb --timing --buffer || TEST_EXIT=$? + - uv run coverage combine + - uv run coverage report + - uv run coverage xml + - uv run coverage html + - exit ${TEST_EXIT:-0} + coverage: '/TOTAL.*? (100(?:\.0+)?|[1-9]?\d(?:\.\d+)?)\%$/' + after_script: + - uv cache prune --ci + artifacts: + expire_in: 1 week + when: always + paths: + - htmlcov/ + reports: + coverage_report: + coverage_format: cobertura + path: coverage.xml deploy-check: stage: test diff --git a/django/{{ cookiecutter.project_slug }}/pyproject.toml b/django/{{ cookiecutter.project_slug }}/pyproject.toml index a073cb9..e59f6c9 100644 --- a/django/{{ cookiecutter.project_slug }}/pyproject.toml +++ b/django/{{ cookiecutter.project_slug }}/pyproject.toml @@ -23,7 +23,53 @@ dependencies = [ [dependency-groups] dev = [ "pre-commit>=4.6.0", + "coverage>=7.17.4", ] production = [ "gunicorn>=26.0.0", -] \ No newline at end of file +] + +[tool.coverage.run] +source = ["."] +branch = true +relative_files = true +parallel = true +concurrency = ["multiprocessing"] + +omit = [ + "*/migrations/*", + "*/tests/*", + "*/tests.py", + "manage.py", + "*/asgi.py", + "*/wsgi.py", + "*/settings/*", + "*/settings.py", + ".venv/*", +] + +[tool.coverage.report] +skip_covered = true +skip_empty = true +precision = 1 + +exclude_also = [ + "def __repr__", + "if TYPE_CHECKING:", + "if typing.TYPE_CHECKING:", + "raise NotImplementedError", + "raise AssertionError", + "if settings.DEBUG", + "if __name__ == .__main__.:", + "@(abc\\.)?abstractmethod", + "class .*\\bProtocol\\):", + "^\\s*\\.\\.\\.$", +] + + +[tool.coverage.html] +directory = "htmlcov" +show_contexts = true + +[tool.coverage.xml] +output = "coverage.xml"