Skip to content

Commit

Permalink
Force ordering of settings and transactional_db fixtures #870
Browse files Browse the repository at this point in the history
  • Loading branch information
bdauvergne committed Sep 24, 2020
1 parent 9d91f0b commit 76bdbd0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pytest_django/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,13 @@ def finalize(self):


@pytest.yield_fixture()
def settings():
def settings(request):
"""A Django settings object which restores changes after the testrun"""
skip_if_no_django()

if 'transactional_db' in request.fixturenames:
request.getfixturevalue('transactional_db')

wrapper = SettingsWrapper()
yield wrapper
wrapper.finalize()
Expand Down
24 changes: 24 additions & 0 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,30 @@ def test_set_non_existent(settings):
]
)

def test_transactional_db_order(self, django_testdir):
django_testdir.create_test_module(
"""
import pytest
from django.conf import settings as django_settings
from django.db.models.signals import post_migrate
@pytest.fixture
def check_settings_in_post_migrate(settings, transactional_db):
def receiver(sender, **kwargs):
assert not hasattr(django_settings, 'TRANSIENT_SETTING')
post_migrate.connect(receiver, weak=False)
def test_set_non_existent(settings, check_settings_in_post_migrate):
settings.TRANSIENT_SETTING = 1
"""
)

result = django_testdir.runpytest_subprocess("--tb=short", "-v", "-s")
assert result.ret == 0
result.stdout.fnmatch_lines(["*test_set_non_existent PASSED*"])


class TestLiveServer:
def test_settings_before(self):
Expand Down

0 comments on commit 76bdbd0

Please sign in to comment.