Skip to content

Commit 0918724

Browse files
committed
update tests to assert deterministic db name suffix logic
1 parent e3a11b8 commit 0918724

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

tests/test_db_setup.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,32 +159,32 @@ def test_xdist_with_reuse(django_testdir):
159159
160160
from .app.models import Item
161161
162-
def _check(settings):
162+
def _check(settings, worker_id):
163163
# Make sure that the database name looks correct
164164
db_name = settings.DATABASES['default']['NAME']
165-
assert db_name.endswith('_gw0') or db_name.endswith('_gw1')
165+
assert db_name == 'test_custom_db_name_{}'.format(worker_id)
166166
167167
assert Item.objects.count() == 0
168168
Item.objects.create(name='foo')
169169
assert Item.objects.count() == 1
170170
171171
172172
@pytest.mark.django_db
173-
def test_a(settings):
174-
_check(settings)
173+
def test_a(settings, worker_id):
174+
_check(settings, worker_id)
175175
176176
177177
@pytest.mark.django_db
178-
def test_b(settings):
179-
_check(settings)
178+
def test_b(settings, worker_id):
179+
_check(settings, worker_id)
180180
181181
@pytest.mark.django_db
182-
def test_c(settings):
183-
_check(settings)
182+
def test_c(settings, worker_id):
183+
_check(settings, worker_id)
184184
185185
@pytest.mark.django_db
186-
def test_d(settings):
187-
_check(settings)
186+
def test_d(settings, worker_id):
187+
_check(settings, worker_id)
188188
"""
189189
)
190190

@@ -270,7 +270,7 @@ def test_sqlite_database_renamed(self, django_testdir):
270270
from django.db import connections
271271
272272
@pytest.mark.django_db
273-
def test_a():
273+
def test_a(worker_id):
274274
(conn_db2, conn_default) = sorted(
275275
connections.all(),
276276
key=lambda conn: conn.alias,
@@ -288,7 +288,7 @@ def test_a():
288288
289289
assert conn_db2.vendor == 'sqlite'
290290
db_name = conn_db2.creation._get_test_db_name()
291-
assert db_name.startswith('test_custom_db_name_gw')
291+
assert db_name == 'test_custom_db_name_{}'.format(worker_id)
292292
"""
293293
)
294294

@@ -377,13 +377,15 @@ def test_db_with_tox_suffix(self, django_testdir, monkeypatch):
377377
from django.db import connections
378378
379379
@pytest.mark.django_db
380-
def test_inner():
380+
def test_inner(worker_id):
381381
382382
(conn, ) = connections.all()
383383
384384
assert conn.vendor == 'sqlite'
385385
db_name = conn.creation._get_test_db_name()
386-
assert db_name.startswith('test_custom_db_name_py37-django22_gw')
386+
assert db_name == 'test_custom_db_name_py37-django22_{}'.format(
387+
worker_id,
388+
)
387389
"""
388390
)
389391

0 commit comments

Comments
 (0)