diff --git a/pytest_django/db_reuse.py b/pytest_django/db_reuse.py index 0dcff90b1..b3f9a2405 100644 --- a/pytest_django/db_reuse.py +++ b/pytest_django/db_reuse.py @@ -95,6 +95,8 @@ def create_test_db_with_reuse(self, verbosity=1, autoclobber=False, This method is a monkey patched version of create_test_db that will not actually create a new database, but just reuse the existing. + + This is only used with Django < 1.8. """ test_database_name = self._get_test_db_name() self.connection.settings_dict['NAME'] = test_database_name diff --git a/pytest_django/fixtures.py b/pytest_django/fixtures.py index 420b507d8..cae7d4763 100644 --- a/pytest_django/fixtures.py +++ b/pytest_django/fixtures.py @@ -43,15 +43,18 @@ def _django_db_setup(request, if request.config.getvalue('nomigrations'): _disable_native_migrations() + db_args = {} with _django_cursor_wrapper: - # Monkey patch Django's setup code to support database re-use - if request.config.getvalue('reuse_db'): - if not request.config.getvalue('create_db'): + if (request.config.getvalue('reuse_db') and + not request.config.getvalue('create_db')): + if get_django_version() >= (1, 8): + db_args['keepdb'] = True + else: monkey_patch_creation_for_db_reuse() # Create the database db_cfg = setup_databases(verbosity=pytest.config.option.verbose, - interactive=False) + interactive=False, **db_args) def teardown_database(): with _django_cursor_wrapper: diff --git a/tests/test_environment.py b/tests/test_environment.py index 4ee912fde..04f45f1fe 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -188,8 +188,8 @@ def test_more_verbose_with_vv(self, testdir): "*PASSED*Destroying test database for alias 'default' ('*')...*"]) def test_more_verbose_with_vv_and_reusedb(self, testdir): - """More verbose output with '-v -v', and --reuse-db.""" - result = testdir.runpytest_subprocess('-s', '-v', '-v', '--reuse-db') + """More verbose output with '-v -v', and --create-db.""" + result = testdir.runpytest_subprocess('-s', '-v', '-v', '--create-db') result.stdout.fnmatch_lines([ "tpkg/test_the_test.py:*Creating test database for alias*", "*PASSED*"])