-
Notifications
You must be signed in to change notification settings - Fork 1.1k
django-debug-toolbar conflicts with django test #1035
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
Comments
Any news on this? |
The Django test runner forcibly sets Try removing the middleware from |
Encountered the same issue. In my case I was overriding |
Are there any updates on this? |
I've had to do this: settings.py
urls.py
It is a very frustrating behaviour. I guess maybe there are other workarounds, but this was enough for now. |
I've tried SamMorrowDrums solution and although it hasn't worked for me, this tweaked version based on his idea is working fine: settings.py
urls.py
|
You can also just override default callback of showing django-debug-toolbar. INTERNAL_IPS = ['127.0.0.1']
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': lambda r: r.environ.get('SERVER_NAME', None) != 'testserver' and (r.META.get('REMOTE_ADDR', None) in INTERNAL_IPS)
} ... or any other method of check on "is test requests" |
Can someone reproduce this to confirm this is still an issue? I haven't been able to reproduce it. |
Hi, I am still facing this issue as well. Using Could this be because of a slightly older django version?
This is my if DEBUG:
...
INSTALLED_APPS += ["debug_toolbar"]
# include as early as possible
MIDDLEWARE = ["debug_toolbar.middleware.DebugToolbarMiddleware"] + MIDDLEWARE
DEBUG_TOOLBAR_PANELS = [
"ddt_request_history.panels.request_history.RequestHistoryPanel",
"debug_toolbar.panels.versions.VersionsPanel",
"debug_toolbar.panels.timer.TimerPanel",
"debug_toolbar.panels.settings.SettingsPanel",
"debug_toolbar.panels.headers.HeadersPanel",
"debug_toolbar.panels.request.RequestPanel",
"debug_toolbar.panels.sql.SQLPanel",
"debug_toolbar.panels.staticfiles.StaticFilesPanel",
"debug_toolbar.panels.templates.TemplatesPanel",
"debug_toolbar.panels.cache.CachePanel",
"debug_toolbar.panels.signals.SignalsPanel",
"debug_toolbar.panels.logging.LoggingPanel",
"debug_toolbar.panels.redirects.RedirectsPanel",
]
INSTALLED_APPS += ["django_nose"]
DEBUG_TOOLBAR_CONFIG = {"SHOW_TOOLBAR_CALLBACK": lambda request: True}
TEST_RUNNER = "django_nose.NoseTestSuiteRunner" |
@shydefoo You can configure your application to avoid including the toolbar during tests via an environment variable. Another option is to run your tests with |
Remove the "if settings.DEBUG" guard. This guard is not necessary and leads to several edge cases in local development setups. This is not necessary as all views are guarded by the require_show_toolbar decorator which uses the SHOW_TOOLBAR_CALLBACK setting. This setting is already capable of enabling/disabling across the application when DEBUG is False. By default, when DEBUG is False, these views return a 404 response. By having the URLs always available, the MIDDLEWARE setting also doesn't need special handling when DEBUG is False, simplifing the overall configuration. An application should be able to reliably reverse URLs regardless of the status of DEBUG. Fixes #1035 Fixes #1043 Fixes #1332
@tim-schilling Yeah, that's what I did. Seems like |
Yep. That did it. from django.conf import settings
....
DEBUG_TOOLBAR_CONFIG = {
...
"SHOW_TOOLBAR_CALLBACK": lambda x: settings.DEBUG,
} |
Reason: DEBUG not uploaded from .env My solution: add environment varibale in pytest.ini #dependency (version of pytest-env is impotant) #pytest.ini [pytest]
env =
DEBUG='True'
python_paths = project_dir/
DJANGO_SETTINGS_MODULE = project_dir.settings
norecursedirs = env/*
addopts = -vv -p no:cacheprovider
testpaths =
project_dir
python_files = test_*.py How run test: pytest |
If
django-debug-toolbar
installed and configured well as the docs, when executing a django project test (eg:python manage.py test
), and djangoreverse
function used in the tests(This is very important), it will get these errors as following:Environment
python: 2.7.14
django: 1.11.9
django-debug-toolbar: 1.9.1
Test file sample
The text was updated successfully, but these errors were encountered: