diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..d4fb73f --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +DJANGO_SETTINGS_MODULE = config.settings diff --git a/{{cookiecutter.project_slug}}/common/test/test_sample.py b/{{cookiecutter.project_slug}}/common/test/test_sample.py new file mode 100644 index 0000000..b20516e --- /dev/null +++ b/{{cookiecutter.project_slug}}/common/test/test_sample.py @@ -0,0 +1,18 @@ +import pytest +from django.urls import reverse, resolve + +from common import views + + +class TestClass: + + @pytest.mark.parametrize( + "url_name, url, view_class", + [ + ("index", "/", views.IndexView), + ], + ) + def test_urls(self, url_name, url, view_class): + resolver = resolve(url) + assert resolver.view_name == url_name + assert resolver.func.view_class == view_class diff --git a/{{cookiecutter.project_slug}}/common/urls.py b/{{cookiecutter.project_slug}}/common/urls.py index fd2a370..e1b7958 100644 --- a/{{cookiecutter.project_slug}}/common/urls.py +++ b/{{cookiecutter.project_slug}}/common/urls.py @@ -1,5 +1,5 @@ from django.conf import settings -from django.conf.urls import url +from django.urls import re_path from django.urls import include, path from common import views @@ -30,7 +30,7 @@ import debug_toolbar urlpatterns += [ - url(r'^__debug__/', include(debug_toolbar.urls)), + re_path(r'^__debug__/', include(debug_toolbar.urls)), ] {%- if cookiecutter.feature_annotations == "on" %} # END_FEATURE debug_toolbar diff --git a/{{cookiecutter.project_slug}}/readme.md b/{{cookiecutter.project_slug}}/readme.md index 7977429..adce47e 100644 --- a/{{cookiecutter.project_slug}}/readme.md +++ b/{{cookiecutter.project_slug}}/readme.md @@ -73,6 +73,11 @@ To run the test suite: python manage.py test ``` +To run pytest tests: +```bash +pytest +``` + To get a test coverage report: ```bash coverage run --source='.' manage.py test; coverage report diff --git a/{{cookiecutter.project_slug}}/requirements.in b/{{cookiecutter.project_slug}}/requirements.in index 4d4115b..7c41adc 100644 --- a/{{cookiecutter.project_slug}}/requirements.in +++ b/{{cookiecutter.project_slug}}/requirements.in @@ -3,6 +3,7 @@ django-environ django-extensions requests psycopg2 +pytest {%- if cookiecutter.feature_annotations == "on" %} ####### OPTIONAL FEATURES #######