|
3 | 3 |
|
4 | 4 | from django.apps import AppConfig
|
5 | 5 | from django.conf import settings
|
6 |
| -from django.core.checks import Warning, register |
| 6 | +from django.core.checks import Error, Warning, register |
7 | 7 | from django.middleware.gzip import GZipMiddleware
|
8 | 8 | from django.utils.module_loading import import_string
|
9 | 9 | from django.utils.translation import gettext_lazy as _
|
@@ -177,7 +177,7 @@ def check_panels(app_configs, **kwargs):
|
177 | 177 | return errors
|
178 | 178 |
|
179 | 179 |
|
180 |
| -@register() |
| 180 | +@register |
181 | 181 | def js_mimetype_check(app_configs, **kwargs):
|
182 | 182 | """
|
183 | 183 | Check that JavaScript files are resolving to the correct content type.
|
@@ -208,7 +208,29 @@ def js_mimetype_check(app_configs, **kwargs):
|
208 | 208 | return []
|
209 | 209 |
|
210 | 210 |
|
211 |
| -@register() |
| 211 | +@register |
| 212 | +def debug_toolbar_installed_when_running_tests_check(app_configs, **kwargs): |
| 213 | + """ |
| 214 | + Check that the toolbar is not being used when tests are running |
| 215 | + """ |
| 216 | + if not settings.DEBUG and dt_settings.get_config()["IS_RUNNING_TESTS"]: |
| 217 | + return [ |
| 218 | + Error( |
| 219 | + "The Django Debug Toolbar can't be used with tests", |
| 220 | + hint="Django changes the DEBUG setting to False when running " |
| 221 | + "tests. By default the Django Debug Toolbar is installed because " |
| 222 | + "DEBUG is set to True. For most cases, you need to avoid installing " |
| 223 | + "the toolbar when running tests. If you feel this check is in error, " |
| 224 | + "you can set `DEBUG_TOOLBAR_CONFIG['IS_RUNNING_TESTS'] = False` to " |
| 225 | + "bypass this check.", |
| 226 | + id="debug_toolbar.E001", |
| 227 | + ) |
| 228 | + ] |
| 229 | + else: |
| 230 | + return [] |
| 231 | + |
| 232 | + |
| 233 | +@register |
212 | 234 | def check_settings(app_configs, **kwargs):
|
213 | 235 | errors = []
|
214 | 236 | USER_CONFIG = getattr(settings, "DEBUG_TOOLBAR_CONFIG", {})
|
|
0 commit comments