Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
Added a new option to avoid forcing of DEBUG setting to False. closes p…
Browse files Browse the repository at this point in the history
  • Loading branch information
bubenkoff authored and mfa committed May 17, 2017
1 parent 13f294e commit 513ea9d
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)

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 @@ -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,
Expand Down Expand Up @@ -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)

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

0 comments on commit 513ea9d

Please sign in to comment.