Repository: pytest-dev/pytest-django (python)

Issue:
why DEBUG is hardcoded to False?
Hi

https://github.com/pytest-dev/pytest-django/blob/master/pytest_django/plugin.py#L239

this looks not too flexible
I tried a lot of things before i found this hardcode - i needed to understand why my liveserver fails, and it returned just standard 500 instead of debug page, and debug is set to True in my test settings
So i think this hardcode should be removed to respect test settings



Discussion:
IIRC the setup with Django's testrunner is also False, to reflect what would be used in production, but I am not certain.

:+1: for a way to configure/override this.

ok i'll prepare PR


Patch:
diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py
--- a/pytest_django/plugin.py
+++ b/pytest_django/plugin.py
@@ -51,6 +51,9 @@ def pytest_addoption(parser):
     group._addoption('--nomigrations',
                      action='store_true', dest='nomigrations', default=False,
                      help='Disable Django 1.7 migrations on test setup')
+    group._addoption('--no-force-no-debug',
+                     action='store_true', dest='noforcenodebug', default=False,
+                     help='Disable forcing DEBUG setting to False on test setup')
     parser.addini(CONFIGURATION_ENV,
                   'django-configurations class to use by pytest-django.')
     group._addoption('--liveserver', default=None,
@@ -236,7 +239,8 @@ def _django_test_environment(request):
     if django_settings_is_configured():
         from django.conf import settings
         from .compat import setup_test_environment, teardown_test_environment
-        settings.DEBUG = False
+        if not request.config.getvalue('noforcenodebug'):
+            settings.DEBUG = False
         setup_test_environment()
         request.addfinalizer(teardown_test_environment)
 


Test patch:
diff --git a/tests/test_django_settings_module.py b/tests/test_django_settings_module.py
--- a/tests/test_django_settings_module.py
+++ b/tests/test_django_settings_module.py
@@ -244,6 +244,31 @@ def test_debug_is_false():
     assert r.ret == 0
 
 
+def test_debug_no_force(testdir, monkeypatch):
+    monkeypatch.delenv('DJANGO_SETTINGS_MODULE')
+    testdir.makeconftest("""
+        from django.conf import settings
+
+        def pytest_configure():
+            settings.configure(SECRET_KEY='set from pytest_configure',
+                               DEBUG=True,
+                               DATABASES={'default': {
+                                   'ENGINE': 'django.db.backends.sqlite3',
+                                   'NAME': ':memory:'}},
+                               INSTALLED_APPS=['django.contrib.auth',
+                                               'django.contrib.contenttypes',])
+    """)
+
+    testdir.makepyfile("""
+        from django.conf import settings
+        def test_debug_is_true():
+            assert settings.DEBUG is True
+    """)
+
+    r = testdir.runpytest('--no-force-no-debug')
+    assert r.ret == 0
+
+
 @pytest.mark.skipif(not hasattr(django, 'setup'),
                     reason="This Django version does not support app loading")
 @pytest.mark.django_project(extra_settings="""