Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit 1aec8fb

Browse files
committed
Simplify tests settings and pytest
1 parent 0288e08 commit 1aec8fb

File tree

2 files changed

+11
-72
lines changed

2 files changed

+11
-72
lines changed

tests/conftest.py

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,12 @@
1+
import os
2+
13
import django
4+
from django.conf import settings
25

36

47
def pytest_configure():
5-
from django.conf import settings
6-
7-
settings.configure(
8-
DEBUG_PROPAGATE_EXCEPTIONS=True,
9-
DATABASES={
10-
'default': {
11-
'ENGINE': 'django.db.backends.sqlite3',
12-
'NAME': 'db.sqlite3'
13-
}
14-
},
15-
SECRET_KEY='r-4p2y=uc56fmqsncog%3h!7hc=y+g)xtz+9y(prx*1o9dpry0',
16-
USE_I18N=True,
17-
USE_L10N=True,
18-
STATIC_URL='/static/',
19-
ROOT_URLCONF='tests.urls',
20-
TEMPLATE_LOADERS=(
21-
'django.template.loaders.filesystem.Loader',
22-
'django.template.loaders.app_directories.Loader',
23-
),
24-
MIDDLEWARE_CLASSES=(
25-
'django.middleware.common.CommonMiddleware',
26-
'django.contrib.sessions.middleware.SessionMiddleware',
27-
'django.middleware.csrf.CsrfViewMiddleware',
28-
'django.contrib.auth.middleware.AuthenticationMiddleware',
29-
'django.contrib.messages.middleware.MessageMiddleware',
30-
),
31-
INSTALLED_APPS = (
32-
'django.contrib.admin',
33-
'django.contrib.auth',
34-
'django.contrib.contenttypes',
35-
'django.contrib.sessions',
36-
'django.contrib.messages',
37-
'django.contrib.staticfiles',
38-
),
39-
PASSWORD_HASHERS=(
40-
'django.contrib.auth.hashers.SHA1PasswordHasher',
41-
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
42-
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
43-
'django.contrib.auth.hashers.BCryptPasswordHasher',
44-
'django.contrib.auth.hashers.MD5PasswordHasher',
45-
'django.contrib.auth.hashers.CryptPasswordHasher',
46-
),
47-
)
48-
49-
try:
50-
import oauth_provider # NOQA
51-
import oauth2 # NOQA
52-
except ImportError:
53-
pass
54-
else:
55-
settings.INSTALLED_APPS += (
56-
'oauth_provider',
57-
)
58-
59-
try:
60-
import provider # NOQA
61-
except ImportError:
62-
pass
63-
else:
64-
settings.INSTALLED_APPS += (
65-
'provider',
66-
'provider.oauth2',
67-
)
68-
69-
if django.VERSION >= (1, 5):
70-
settings.INSTALLED_APPS += ('tests',)
8+
if not settings.configured:
9+
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
7110

7211
try:
7312
django.setup()

tests/settings.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import django
2+
13
# Django settings for testproject project.
24

35
DEBUG = True
@@ -64,7 +66,7 @@
6466
MEDIA_URL = ''
6567

6668
# Make this unique, and don't share it with anybody.
67-
SECRET_KEY = 'r-4p2y=uc56fmqsncog%3h!7hc=y+g)xtz+9y(prx*1o9dpry0',
69+
SECRET_KEY = 'r-4p2y=uc56fmqsncog%3h!7hc=y+g)xtz+9y(prx*1o9dpry0'
6870

6971
# List of callables that know how to import templates from various sources.
7072
TEMPLATE_LOADERS = (
@@ -118,6 +120,9 @@
118120
'provider.oauth2',
119121
)
120122

123+
if django.VERSION >= (1, 5):
124+
INSTALLED_APPS += ('tests',)
125+
121126
STATIC_URL = '/static/'
122127

123128
PASSWORD_HASHERS = (
@@ -130,8 +135,3 @@
130135
)
131136

132137
AUTH_USER_MODEL = 'auth.User'
133-
134-
import django
135-
136-
if django.VERSION >= (1, 5):
137-
INSTALLED_APPS += ('tests',)

0 commit comments

Comments
 (0)