-
Notifications
You must be signed in to change notification settings - Fork 1.1k
'djdt' is not a registered namespace #1405 #1889
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
Changes from all commits
5b2b969
2edf71e
3312069
83e9739
1193e0c
3affaea
36cf020
8bf25e9
46f64c4
5941710
df02d33
18eaab5
2c21976
e944857
7f5da54
713c4cf
65bf1cb
c7ad698
18ead4e
aef39b2
a515cc1
4820a9a
424bf02
c620b7c
effccff
902665c
3cb2f7c
a182401
9d906fb
0e90884
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Add tests to example app to check how the toolbar is used | ||
# when running tests for a project. | ||
# See https://github.com/jazzband/django-debug-toolbar/issues/1405 | ||
|
||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
|
||
class ViewTestCase(TestCase): | ||
def test_index(self): | ||
response = self.client.get(reverse("home")) | ||
assert response.status_code == 200 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
from unittest.mock import patch | ||
|
||
from django.core.checks import Warning, run_checks | ||
from django.core.checks import Error, Warning, run_checks | ||
from django.test import SimpleTestCase, override_settings | ||
|
||
from debug_toolbar import settings as dt_settings | ||
from debug_toolbar.apps import debug_toolbar_installed_when_running_tests_check | ||
|
||
|
||
class ChecksTestCase(SimpleTestCase): | ||
@override_settings( | ||
|
@@ -97,7 +100,7 @@ def test_panels_is_empty(self): | |
hint="Set DEBUG_TOOLBAR_PANELS to a non-empty list in your " | ||
"settings.py.", | ||
id="debug_toolbar.W005", | ||
) | ||
), | ||
], | ||
) | ||
|
||
|
@@ -236,8 +239,45 @@ def test_check_w007_invalid(self, mocked_guess_type): | |
], | ||
) | ||
|
||
def test_debug_toolbar_installed_when_running_tests(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why you're modifying the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we were to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know what you think of the new comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! No further comments :-) |
||
with self.settings(DEBUG=True): | ||
# Update the config options because self.settings() | ||
# would require redefining DEBUG_TOOLBAR_CONFIG entirely. | ||
dt_settings.get_config()["IS_RUNNING_TESTS"] = True | ||
errors = debug_toolbar_installed_when_running_tests_check(None) | ||
self.assertEqual(len(errors), 0) | ||
|
||
dt_settings.get_config()["IS_RUNNING_TESTS"] = False | ||
errors = debug_toolbar_installed_when_running_tests_check(None) | ||
self.assertEqual(len(errors), 0) | ||
with self.settings(DEBUG=False): | ||
dt_settings.get_config()["IS_RUNNING_TESTS"] = False | ||
errors = debug_toolbar_installed_when_running_tests_check(None) | ||
self.assertEqual(len(errors), 0) | ||
|
||
dt_settings.get_config()["IS_RUNNING_TESTS"] = True | ||
errors = debug_toolbar_installed_when_running_tests_check(None) | ||
self.assertEqual( | ||
tim-schilling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
errors, | ||
[ | ||
Error( | ||
"The Django Debug Toolbar can't be used with tests", | ||
hint="Django changes the DEBUG setting to False when running " | ||
"tests. By default the Django Debug Toolbar is installed because " | ||
"DEBUG is set to True. For most cases, you need to avoid installing " | ||
"the toolbar when running tests. If you feel this check is in error, " | ||
"you can set `DEBUG_TOOLBAR_CONFIG['IS_RUNNING_TESTS'] = False` to " | ||
"bypass this check.", | ||
id="debug_toolbar.E001", | ||
) | ||
], | ||
) | ||
|
||
@override_settings( | ||
DEBUG_TOOLBAR_CONFIG={"OBSERVE_REQUEST_CALLBACK": lambda request: False} | ||
DEBUG_TOOLBAR_CONFIG={ | ||
"OBSERVE_REQUEST_CALLBACK": lambda request: False, | ||
"IS_RUNNING_TESTS": False, | ||
} | ||
) | ||
def test_observe_request_callback_specified(self): | ||
errors = run_checks() | ||
|
Uh oh!
There was an error while loading. Please reload this page.