Skip to content

Commit f725579

Browse files
authored
tests: fix db_helpers.drop_database: use suffix; cleanup (#812)
* tests: fix db_helpers.drop_database: use suffix `test_xdist_with_reuse` uses `drop_database("gw0")`, where `"gw0"` is meant to be a suffix, not the whole name. * test_xdist_with_reuse: cleanup DBs
1 parent ec9d832 commit f725579

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

pytest_django_test/db_helpers.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ def skip_if_sqlite_in_memory():
6161
pytest.skip("Do not test db reuse since database does not support it")
6262

6363

64-
def drop_database(name=TEST_DB_NAME):
64+
def _get_db_name(db_suffix=None):
65+
name = TEST_DB_NAME
66+
if db_suffix:
67+
name = "%s_%s" % (name, db_suffix)
68+
return name
69+
70+
71+
def drop_database(db_suffix=None):
72+
name = _get_db_name(db_suffix)
6573
db_engine = get_db_engine()
6674

6775
if db_engine == "postgresql_psycopg2":
@@ -83,12 +91,9 @@ def drop_database(name=TEST_DB_NAME):
8391

8492

8593
def db_exists(db_suffix=None):
86-
name = TEST_DB_NAME
94+
name = _get_db_name(db_suffix)
8795
db_engine = get_db_engine()
8896

89-
if db_suffix:
90-
name = "%s_%s" % (name, db_suffix)
91-
9297
if db_engine == "postgresql_psycopg2":
9398
r = run_cmd("psql", name, "-c", "SELECT 1")
9499
return r.status_code == 0

tests/test_db_setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def test_xdist_with_reuse(django_testdir):
152152

153153
drop_database("gw0")
154154
drop_database("gw1")
155+
assert not db_exists("gw0")
156+
assert not db_exists("gw1")
155157

156158
django_testdir.create_test_module(
157159
"""
@@ -214,6 +216,10 @@ def test_d(settings):
214216
result.stdout.fnmatch_lines(["*PASSED*test_c*"])
215217
result.stdout.fnmatch_lines(["*PASSED*test_d*"])
216218

219+
# Cleanup.
220+
drop_database("gw0")
221+
drop_database("gw1")
222+
217223

218224
class TestSqliteWithXdist:
219225

0 commit comments

Comments
 (0)