Skip to content

Commit

Permalink
Ensure SetupDjangoTest cleans up after itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
tail committed Sep 23, 2015
1 parent b481a40 commit efa53b2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import django
from django.conf import settings
from exam import before
from exam import before, after


class SetupDjangoTest(object):
Expand All @@ -9,8 +9,16 @@ class SetupDjangoTest(object):
def setup_django(self):
# For Django 1.7+, we need to run `django.setup()` first.
if hasattr(django, 'setup'):
self.__original_installed_apps = settings.INSTALLED_APPS
settings.INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.sessions',
) + settings.INSTALLED_APPS

django.setup()

@after
def undo_setup_django(self):
if hasattr(django, 'setup'):
settings.INSTALLED_APPS = self.__original_installed_apps
del self.__original_installed_apps

0 comments on commit efa53b2

Please sign in to comment.