Skip to content
Closed
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
55 changes: 32 additions & 23 deletions docs/tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,61 @@
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",
"NAME": ":memory:",
}
},
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",),
)


Expand All @@ -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:])
34 changes: 34 additions & 0 deletions docs/tests/settings.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions docs/tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
]
7 changes: 4 additions & 3 deletions docs/urls.py
Original file line number Diff line number Diff line change
@@ -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 += [
Expand Down
7 changes: 3 additions & 4 deletions example/example/urls.py
Original file line number Diff line number Diff line change
@@ -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")),
]
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
DJANGO_SETTINGS_MODULE = docs.tests.settings
pythonpath = . example
python_files = tests.py test_*.py *_tests.py
Loading