Skip to content

Commit

Permalink
Merge pull request #231 from pytest-dev/no-force-debug
Browse files Browse the repository at this point in the history
Added a new option  to avoid forcing of DEBUG setting to False
  • Loading branch information
pelme committed Jul 26, 2015
2 parents fe7d280 + 5297b81 commit 73fe800
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
8 changes: 8 additions & 0 deletions 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)

This comment has been minimized.

Copy link
@blueyed

blueyed Jul 26, 2015

Contributor

Typo: --no-foce-no-debug


2.8.0
-----

Expand Down
12 changes: 12 additions & 0 deletions docs/configuring_django.rst
Expand Up @@ -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.
6 changes: 5 additions & 1 deletion pytest_django/plugin.py
Expand Up @@ -54,6 +54,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,
Expand Down Expand Up @@ -251,7 +254,8 @@ def _django_test_environment(request):
_setup_django()
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)

Expand Down
25 changes: 25 additions & 0 deletions tests/test_django_settings_module.py
Expand Up @@ -245,6 +245,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="""
Expand Down

0 comments on commit 73fe800

Please sign in to comment.