Skip to content

Commit 6677f63

Browse files
committed
Force ordering of settings and transactional_db fixtures #870
1 parent 9d91f0b commit 6677f63

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

pytest_django/fixtures.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,13 @@ def finalize(self):
354354

355355

356356
@pytest.yield_fixture()
357-
def settings():
357+
def settings(request):
358358
"""A Django settings object which restores changes after the testrun"""
359359
skip_if_no_django()
360360

361+
if 'transactional_db' in request.fixturenames:
362+
request.getfixturevalue('transactional_db')
363+
361364
wrapper = SettingsWrapper()
362365
yield wrapper
363366
wrapper.finalize()

tests/test_fixtures.py

+24
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,30 @@ def test_set_non_existent(settings):
316316
]
317317
)
318318

319+
def test_transactional_db_order(self, django_testdir):
320+
django_testdir.create_test_module(
321+
"""
322+
import pytest
323+
324+
from django.conf import settings as django_settings
325+
from django.db.models.signals import post_migrate
326+
327+
@pytest.fixture
328+
def check_settings_in_post_migrate(settings, transactional_db):
329+
def receiver(sender, **kwargs):
330+
assert not hasattr(django_settings, 'TRANSIENT_SETTING')
331+
332+
post_migrate.connect(receiver, weak=False)
333+
334+
def test_set_non_existent(settings, check_settings_in_post_migrate):
335+
settings.TRANSIENT_SETTING = 1
336+
"""
337+
)
338+
339+
result = django_testdir.runpytest_subprocess("-v")
340+
assert result.ret == 0
341+
result.stdout.fnmatch_lines(["*test_set_non_existent PASSED*"])
342+
319343

320344
class TestLiveServer:
321345
def test_settings_before(self):

0 commit comments

Comments
 (0)