Skip to content

Commit 73fe800

Browse files
committed
Merge pull request #231 from pytest-dev/no-force-debug
Added a new option to avoid forcing of DEBUG setting to False
2 parents fe7d280 + 5297b81 commit 73fe800

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
@@ -54,6 +54,9 @@ def pytest_addoption(parser):
5454
group._addoption('--nomigrations',
5555
action='store_true', dest='nomigrations', default=False,
5656
help='Disable Django 1.7 migrations on test setup')
57+
group._addoption('--no-force-no-debug',
58+
action='store_true', dest='noforcenodebug', default=False,
59+
help='Disable forcing DEBUG setting to False on test setup')
5760
parser.addini(CONFIGURATION_ENV,
5861
'django-configurations class to use by pytest-django.')
5962
group._addoption('--liveserver', default=None,
@@ -251,7 +254,8 @@ def _django_test_environment(request):
251254
_setup_django()
252255
from django.conf import settings
253256
from .compat import setup_test_environment, teardown_test_environment
254-
settings.DEBUG = False
257+
if not request.config.getvalue('noforcenodebug'):
258+
settings.DEBUG = False
255259
setup_test_environment()
256260
request.addfinalizer(teardown_test_environment)
257261

tests/test_django_settings_module.py

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

247247

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

0 commit comments

Comments
 (0)