diff --git a/docs/tests/runtests.py b/docs/tests/runtests.py index 016363e..a2ac8b6 100644 --- a/docs/tests/runtests.py +++ b/docs/tests/runtests.py @@ -7,39 +7,46 @@ for your app and run the tests as if you were calling ``./manage.py test``. """ + +import collections import os import sys -import collections from django.conf import settings collections.Callable = collections.abc.Callable EXTERNAL_APPS = [ - 'django.contrib.admin', - 'django.contrib.admindocs', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.messages', - 'django.contrib.sessions', - 'django.contrib.staticfiles', - 'django.contrib.sitemaps', - 'django.contrib.sites', + "django.contrib.admin", + "django.contrib.admindocs", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.messages", + "django.contrib.sessions", + "django.contrib.staticfiles", + "django.contrib.sitemaps", + "django.contrib.sites", ] INTERNAL_APPS = [ - 'django_nose', - 'docs', + "django_nose", + "docs", ] INSTALLED_APPS = EXTERNAL_APPS + INTERNAL_APPS COVERAGE_MODULE_EXCLUDES = [ - 'tests$', 'settings$', 'urls$', 'locale$', - 'migrations', 'fixtures', 'admin$', 'django_extensions', + "tests$", + "settings$", + "urls$", + "locale$", + "migrations", + "fixtures", + "admin$", + "django_extensions", ] COVERAGE_MODULE_EXCLUDES += EXTERNAL_APPS if not settings.configured: settings.configure( - SECRET_KEY='sdfkjsdfsdiuy7yruhsdvyggvbis', + SECRET_KEY="sdfkjsdfsdiuy7yruhsdvyggvbis", DATABASES={ "default": { "ENGINE": "django.db.backends.sqlite3", @@ -47,15 +54,14 @@ } }, INSTALLED_APPS=INSTALLED_APPS, - ROOT_URLCONF='docs.tests.urls', - TEMPLATE_DIRS=( - os.path.join(os.path.dirname(__file__), '../../templates'), - ), + ROOT_URLCONF="docs.tests.urls", + TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), "../../templates"),), COVERAGE_MODULE_EXCLUDES=COVERAGE_MODULE_EXCLUDES, COVERAGE_REPORT_HTML_OUTPUT_DIR=os.path.join( - os.path.dirname(__file__), 'coverage'), + os.path.dirname(__file__), "coverage" + ), USE_TZ=True, - PASSWORD_HASHERS = ('django.contrib.auth.hashers.MD5PasswordHasher',), + PASSWORD_HASHERS=("django.contrib.auth.hashers.MD5PasswordHasher",), ) @@ -64,13 +70,16 @@ class NoseCoverageTestRunner(NoseTestSuiteRunner): """Custom test runner that uses nose and coverage""" + pass def runtests(*test_args): - failures = NoseCoverageTestRunner(verbosity=2, interactive=True).run_tests(test_args) + failures = NoseCoverageTestRunner(verbosity=2, interactive=False).run_tests( + test_args + ) sys.exit(failures) -if __name__ == '__main__': +if __name__ == "__main__": runtests(*sys.argv[1:]) diff --git a/docs/tests/settings.py b/docs/tests/settings.py new file mode 100644 index 0000000..20214f5 --- /dev/null +++ b/docs/tests/settings.py @@ -0,0 +1,34 @@ +SECRET_KEY = "secret" +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "docs", +] +ROOT_URLCONF = "docs.tests.urls" +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": ":memory:", + } +} +USE_TZ = True +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] +DOCS_ROOT = None diff --git a/docs/tests/urls.py b/docs/tests/urls.py index 0771751..c89cf4c 100644 --- a/docs/tests/urls.py +++ b/docs/tests/urls.py @@ -4,9 +4,9 @@ you can actually reach the app's views (provided it has any views, of course). """ -from django.urls.conf import include, re_path +from django.urls import include, re_path urlpatterns = [ - re_path(r'^', include('docs.urls')), + re_path(r"^", include("docs.urls")), ] diff --git a/docs/urls.py b/docs/urls.py index 9bd1a50..cfc54b5 100644 --- a/docs/urls.py +++ b/docs/urls.py @@ -1,11 +1,12 @@ -from django.urls.conf import re_path -from docs.views import DocsRootView, serve_docs, DOCS_DIRHTML +from django.urls import re_path + +from docs.views import DOCS_DIRHTML, DocsRootView, serve_docs urlpatterns = [] if not DOCS_DIRHTML: urlpatterns += [ - re_path(r'^$', DocsRootView.as_view(permanent=True), name='docs_root'), + re_path(r"^$", DocsRootView.as_view(permanent=True), name="docs_root"), ] urlpatterns += [ diff --git a/example/example/urls.py b/example/example/urls.py index 5837558..0c94300 100644 --- a/example/example/urls.py +++ b/example/example/urls.py @@ -1,8 +1,7 @@ -from django.conf.urls import url, include from django.contrib import admin - +from django.urls import include, re_path urlpatterns = [ - url(r'^admin/', admin.site.urls), - url(r'^docs/', include('docs.urls')), + re_path(r"^admin/", admin.site.urls), + re_path(r"^docs/", include("docs.urls")), ] diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..3b346c1 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +DJANGO_SETTINGS_MODULE = docs.tests.settings +pythonpath = . example +python_files = tests.py test_*.py *_tests.py