Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new option to avoid forcing of DEBUG setting to False #231

Merged
merged 1 commit into from Jul 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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