Skip to content

Commit

Permalink
Use django.test.utils to initialize test database
Browse files Browse the repository at this point in the history
Removes the need to import and instantiate DiscoverRunner.

This also allows passing verbosity=0 when creating the database to
squelch some noise during tests:

    Creating test database for alias 'default'...
    Creating test database for alias 'replica'...

Available since Django 1.11.
  • Loading branch information
jdufresne authored and rbarrois committed Nov 3, 2020
1 parent 1957bd3 commit 7d6514d
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions tests/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from django.conf import settings
from django.db.models import signals
from django.test import utils as django_test_utils
from django.test.runner import DiscoverRunner as DjangoTestSuiteRunner

import factory.django

Expand All @@ -34,18 +33,12 @@

def setUpModule():
django_test_utils.setup_test_environment()
runner = DjangoTestSuiteRunner()
runner_state = runner.setup_databases()
test_state.update({
'runner': runner,
'runner_state': runner_state,
})
runner_state = django_test_utils.setup_databases(verbosity=0, interactive=False)
test_state['runner_state'] = runner_state


def tearDownModule():
runner = test_state['runner']
runner_state = test_state['runner_state']
runner.teardown_databases(runner_state)
django_test_utils.teardown_databases(test_state['runner_state'], verbosity=0)
django_test_utils.teardown_test_environment()


Expand Down

0 comments on commit 7d6514d

Please sign in to comment.