Skip to content

Commit 5297b81

Browse files
committed
Added a new option to avoid forcing of DEBUG setting to False. closes #228
1 parent 1f279de commit 5297b81

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

docs/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
Unreleased
5+
----------
6+
7+
Features
8+
^^^^^^^^
9+
10+
* Added a new option `--no-foce-no-debug` to avoid forcing of DEBUG setting to False (bubenkoff)
11+
412
2.8.0
513
-----
614

docs/configuring_django.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,15 @@ This can be done from your project's ``conftest.py`` file::
7474
def pytest_configure():
7575
settings.configure(DATABASES=...)
7676

77+
78+
``DEBUG`` setting during the test run
79+
-------------------------------------
80+
81+
Default django test runner behavior is to force DEBUG setting to False. So does the ``pytest-django``.
82+
But sometimes, especially for functional tests, you might want to avoid this, to debug why certain page does not work.
83+
84+
Command Line Option::
85+
86+
$ py.test --no-force-no-debug
87+
88+
will make sure that DEBUG is not forced to False, so you can set it to True in your test settings.

pytest_django/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def pytest_addoption(parser):
5151
group._addoption('--nomigrations',
5252
action='store_true', dest='nomigrations', default=False,
5353
help='Disable Django 1.7 migrations on test setup')
54+
group._addoption('--no-force-no-debug',
55+
action='store_true', dest='noforcenodebug', default=False,
56+
help='Disable forcing DEBUG setting to False on test setup')
5457
parser.addini(CONFIGURATION_ENV,
5558
'django-configurations class to use by pytest-django.')
5659
group._addoption('--liveserver', default=None,
@@ -236,7 +239,8 @@ def _django_test_environment(request):
236239
if django_settings_is_configured():
237240
from django.conf import settings
238241
from .compat import setup_test_environment, teardown_test_environment
239-
settings.DEBUG = False
242+
if not request.config.getvalue('noforcenodebug'):
243+
settings.DEBUG = False
240244
setup_test_environment()
241245
request.addfinalizer(teardown_test_environment)
242246

tests/test_django_settings_module.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,31 @@ def test_debug_is_false():
244244
assert r.ret == 0
245245

246246

247+
def test_debug_no_force(testdir, monkeypatch):
248+
monkeypatch.delenv('DJANGO_SETTINGS_MODULE')
249+
testdir.makeconftest("""
250+
from django.conf import settings
251+
252+
def pytest_configure():
253+
settings.configure(SECRET_KEY='set from pytest_configure',
254+
DEBUG=True,
255+
DATABASES={'default': {
256+
'ENGINE': 'django.db.backends.sqlite3',
257+
'NAME': ':memory:'}},
258+
INSTALLED_APPS=['django.contrib.auth',
259+
'django.contrib.contenttypes',])
260+
""")
261+
262+
testdir.makepyfile("""
263+
from django.conf import settings
264+
def test_debug_is_true():
265+
assert settings.DEBUG is True
266+
""")
267+
268+
r = testdir.runpytest('--no-force-no-debug')
269+
assert r.ret == 0
270+
271+
247272
@pytest.mark.skipif(not hasattr(django, 'setup'),
248273
reason="This Django version does not support app loading")
249274
@pytest.mark.django_project(extra_settings="""

0 commit comments

Comments
 (0)