Skip to content

Commit 7c84e7f

Browse files
committed
Look for django.conf in django_settings_is_configured
Fixes: pytest-dev#190
1 parent 619fd87 commit 7c84e7f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pytest_django/lazy_django.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,28 @@ def test_anything():
263263
result.stdout.fnmatch_lines(['*IMPORT: populating=True,ready=False*'])
264264
result.stdout.fnmatch_lines(['*READY(): populating=True*'])
265265
result.stdout.fnmatch_lines(['*TEST: populating=False,ready=True*'])
266+
267+
268+
def test_no_ds_but_django_imported(testdir, monkeypatch):
269+
"""pytest-django should not bail out, if "django" has been imported
270+
somewhere, e.g. via pytest-splinter."""
271+
272+
monkeypatch.delenv('DJANGO_SETTINGS_MODULE')
273+
274+
testdir.makepyfile("""
275+
import os
276+
import django
277+
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+
283+
def test_env():
284+
assert 'DJANGO_SETTINGS_MODULE' not in os.environ
285+
286+
def test_cfg(pytestconfig):
287+
assert pytestconfig.option.ds is None
288+
""")
289+
r = testdir.runpytest('-s')
290+
assert r.ret == 0

0 commit comments

Comments
 (0)