Skip to content

Commit ac2b3c7

Browse files
committed
Look for django.conf in django_settings_is_configured
1 parent ec97b76 commit ac2b3c7

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pytest_django/lazy_django.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def skip_if_no_django():
1717
def django_settings_is_configured():
1818
# Avoid importing Django if it has not yet been imported
1919
if not os.environ.get('DJANGO_SETTINGS_MODULE') \
20-
and 'django' not in sys.modules:
20+
and 'django.conf' not in sys.modules:
2121
return False
2222

2323
# If DJANGO_SETTINGS_MODULE is defined at this point, Django is assumed to

tests/test_django_settings_module.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import django
77
import pytest
88

9-
from pytest_django.lazy_django import django_settings_is_configured
10-
119

1210
BARE_SETTINGS = '''
1311
# At least one database must be configured
@@ -267,17 +265,21 @@ def test_anything():
267265
result.stdout.fnmatch_lines(['*TEST: populating=False,ready=True*'])
268266

269267

270-
def test_django_settings_is_configured():
271-
assert django_settings_is_configured() is False
272-
273-
274-
def test_no_ds_but_django_imported(testdir):
268+
def test_no_ds_but_django_imported(testdir, monkeypatch):
275269
"""pytest-django should not bail out, if "django" has been imported
276270
somewhere, e.g. via pytest-splinter."""
271+
272+
monkeypatch.delenv('DJANGO_SETTINGS_MODULE')
273+
277274
testdir.makepyfile("""
278275
import os
279276
import django
280277
278+
from pytest_django.lazy_django import django_settings_is_configured
279+
280+
def test_django_settings_is_configured():
281+
assert django_settings_is_configured() is False
282+
281283
def test_env():
282284
assert 'DJANGO_SETTINGS_MODULE' not in os.environ
283285

0 commit comments

Comments
 (0)