@@ -275,6 +275,81 @@ def test_debug_is_false():
275275 assert r .ret == 0
276276
277277
278+ def test_no_debug_override (testdir , monkeypatch ):
279+ monkeypatch .delenv ('DJANGO_SETTINGS_MODULE' )
280+ testdir .makeconftest ("""
281+ from django.conf import settings
282+
283+ def pytest_configure():
284+ settings.configure(SECRET_KEY='set from pytest_configure',
285+ DEBUG=True,
286+ DATABASES={'default': {
287+ 'ENGINE': 'django.db.backends.sqlite3',
288+ 'NAME': ':memory:'}},
289+ INSTALLED_APPS=['django.contrib.auth',
290+ 'django.contrib.contenttypes',])
291+ """ )
292+
293+ testdir .makepyfile ("""
294+ from django.conf import settings
295+ def test_debug_is_unchanged():
296+ assert settings.DEBUG is True
297+ """ )
298+
299+ r = testdir .runpytest_subprocess ('--django-debug=None' )
300+ assert r .ret == 0
301+
302+
303+ def test_override_debug_to_false (testdir , monkeypatch ):
304+ monkeypatch .delenv ('DJANGO_SETTINGS_MODULE' )
305+ testdir .makeconftest ("""
306+ from django.conf import settings
307+
308+ def pytest_configure():
309+ settings.configure(SECRET_KEY='set from pytest_configure',
310+ DEBUG=True,
311+ DATABASES={'default': {
312+ 'ENGINE': 'django.db.backends.sqlite3',
313+ 'NAME': ':memory:'}},
314+ INSTALLED_APPS=['django.contrib.auth',
315+ 'django.contrib.contenttypes',])
316+ """ )
317+
318+ testdir .makepyfile ("""
319+ from django.conf import settings
320+ def test_debug_is_false():
321+ assert settings.DEBUG is False
322+ """ )
323+
324+ r = testdir .runpytest_subprocess ('--django-debug=False' )
325+ assert r .ret == 0
326+
327+
328+ def test_override_debug_to_true (testdir , monkeypatch ):
329+ monkeypatch .delenv ('DJANGO_SETTINGS_MODULE' )
330+ testdir .makeconftest ("""
331+ from django.conf import settings
332+
333+ def pytest_configure():
334+ settings.configure(SECRET_KEY='set from pytest_configure',
335+ DEBUG=True,
336+ DATABASES={'default': {
337+ 'ENGINE': 'django.db.backends.sqlite3',
338+ 'NAME': ':memory:'}},
339+ INSTALLED_APPS=['django.contrib.auth',
340+ 'django.contrib.contenttypes',])
341+ """ )
342+
343+ testdir .makepyfile ("""
344+ from django.conf import settings
345+ def test_debug_is_true():
346+ assert settings.DEBUG is True
347+ """ )
348+
349+ r = testdir .runpytest_subprocess ('--django-debug=True' )
350+ assert r .ret == 0
351+
352+
278353@pytest .mark .skipif (not hasattr (django , 'setup' ),
279354 reason = "This Django version does not support app loading" )
280355@pytest .mark .django_project (extra_settings = """
0 commit comments