Skip to content

Commit b44d645

Browse files
committed
Fix --reuse-db and --create-db not working together. Fixes #411
1 parent 94cccb9 commit b44d645

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pytest_django/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def teardown_database():
9999
verbosity=pytest.config.option.verbose,
100100
)
101101

102-
if not django_db_keepdb:
102+
if not request.config.getvalue('reuse_db'):
103103
request.addfinalizer(teardown_database)
104104

105105

tests/test_db_setup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ def test_db_can_be_accessed():
2020

2121
result = django_testdir.runpytest_subprocess('-v', '--reuse-db')
2222
assert result.ret == 0
23+
assert db_exists()
24+
result.stdout.fnmatch_lines([
25+
"*test_db_can_be_accessed PASSED*",
26+
])
27+
28+
29+
def test_db_reuse_create_simple(django_testdir):
30+
"A test for all backends to check that `--reuse-db` with `--create-db` works."
31+
django_testdir.create_test_module('''
32+
import pytest
33+
34+
from .app.models import Item
35+
36+
@pytest.mark.django_db
37+
def test_db_can_be_accessed():
38+
assert Item.objects.count() == 0
39+
''')
40+
41+
result = django_testdir.runpytest_subprocess('-v', '--reuse-db', '--create-db')
42+
assert result.ret == 0
43+
assert db_exists()
2344
result.stdout.fnmatch_lines([
2445
"*test_db_can_be_accessed PASSED*",
2546
])

0 commit comments

Comments
 (0)