diff --git a/docs/changelog.rst b/docs/changelog.rst index 4d9884e51..4eef49ae3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,14 @@ Changelog ========= +Unreleased +---------- + +Features +^^^^^^^^ + +* Added a new option `--no-foce-no-debug` to avoid forcing of DEBUG setting to False (bubenkoff) + 2.8.0 ----- diff --git a/docs/configuring_django.rst b/docs/configuring_django.rst index 6281434b2..4181c0d10 100644 --- a/docs/configuring_django.rst +++ b/docs/configuring_django.rst @@ -74,3 +74,15 @@ This can be done from your project's ``conftest.py`` file:: def pytest_configure(): settings.configure(DATABASES=...) + +``DEBUG`` setting during the test run +------------------------------------- + +Default django test runner behavior is to force DEBUG setting to False. So does the ``pytest-django``. +But sometimes, especially for functional tests, you might want to avoid this, to debug why certain page does not work. + +Command Line Option:: + + $ py.test --no-force-no-debug + +will make sure that DEBUG is not forced to False, so you can set it to True in your test settings. diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 31a967aac..24800187f 100644 --- 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) diff --git a/tests/test_django_settings_module.py b/tests/test_django_settings_module.py index 93e1dfa08..10b6682b0 100644 --- 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="""