Skip to content

Commit

Permalink
fix: Make django-app unit tests work; test this in cookiecutter CI
Browse files Browse the repository at this point in the history
- Add placeholder test to allow pytest to run without complaining about
  not finding any tests (exit code 5).
- Trim tox default envs to just pytest ones; add `doc` env explicitly to
  `test-all` Makefile target to compensate.

This just fixes cookiecutter-django-app for now; other cookiecutters can
be fixed once this is shown to work.
  • Loading branch information
timmc-edx committed Jul 11, 2022
1 parent 7670bd0 commit 68444ec
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ Change Log
This file loosely adheres to the structure of https://keepachangelog.com/,
but in reStructuredText instead of Markdown.
Unreleased
----------

Fixed
~~~~~

- Ensure django-app unit tests will work, and test this in cookiecutter's own CI

2022-07-11
----------

Expand Down
3 changes: 2 additions & 1 deletion cookiecutter-django-app/{{cookiecutter.repo_name}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pii_check: ## check for PII annotations on all Django models
piptools: ## install pinned version of pip-compile and pip-sync
pip install -r requirements/pip.txt
pip install -r requirements/pip-tools.txt

requirements: piptools ## install development environment requirements
pip-sync -q requirements/dev.txt requirements/private.*

Expand All @@ -68,6 +68,7 @@ diff_cover: test ## find diff lines that need test coverage

test-all: quality pii_check ## run tests on every supported Python/Django combination
tox
tox -e docs

validate: quality pii_check test ## run tests and quality checks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ class Test{{ model }}:
def test_something(self):
"""TODO: Write real test cases."""
{%- endfor -%}
{%- else %}


def test_placeholder():
"""
Placeholder to allow pytest to succeed before real tests are in place.
(If there are no tests, it will exit with code 5.)
"""
{%- endif %}
2 changes: 1 addition & 1 deletion cookiecutter-django-app/{{cookiecutter.repo_name}}/tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py38-django{32,40}, quality, docs, pii_check
envlist = py38-django{32,40}

[doc8]
; D001 = Line too long
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cookiecutter_django_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,11 @@ def test_quality(options_baked):
sh.doc8("docs", ignore_path="docs/_build")
except sh.ErrorReturnCode as exc:
pytest.fail(str(exc))


def test_tests(options_baked):
"""Make sure the tox default tests work"""
try:
run_in_virtualenv('pip install -r requirements/ci.txt; tox')
except sh.ErrorReturnCode as exc:
pytest.fail(str(exc.stderr))

0 comments on commit 68444ec

Please sign in to comment.