diff --git a/docs/changes.rst b/docs/changes.rst index 0bac18c20..3a96e3058 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -6,6 +6,8 @@ Pending * Removed some CSS which wasn't carefully limited to the toolbar's elements. * Stopped assuming that ``INTERNAL_IPS`` is a list. +* Added a section to the installation docs about running tests in projects + where the toolbar is being used. 4.4.1 (2024-05-26) diff --git a/docs/configuration.rst b/docs/configuration.rst index 7db7ad41e..04694aceb 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -72,6 +72,8 @@ Toolbar options The toolbar searches for this string in the HTML and inserts itself just before. +.. _IS_RUNNING_TESTS: + * ``IS_RUNNING_TESTS`` Default: ``"test" in sys.argv`` diff --git a/docs/installation.rst b/docs/installation.rst index 3644bdd5c..657450fac 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -156,6 +156,39 @@ option. able to get the toolbar to work with your docker installation, review the code in ``debug_toolbar.middleware.show_toolbar``. +7. Disable the toolbar when running tests (optional) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +If you're running tests in your project you shouldn't activate the toolbar. You +can do this by adding another setting: + +.. code-block:: python + + TESTING = "test" in sys.argv + + if not TESTING: + INSTALLED_APPS = [ + *INSTALLED_APPS, + "debug_toolbar", + ] + MIDDLEWARE = [ + "debug_toolbar.middleware.DebugToolbarMiddleware", + *MIDDLEWARE, + ] + +You should also modify your URLconf file: + +.. code-block:: python + + if not settings.TESTING: + urlpatterns = [ + *urlpatterns, + path("__debug__/", include("debug_toolbar.urls")), + ] + +Alternatively, you can check out the :ref:`IS_RUNNING_TESTS ` +option. + Troubleshooting ---------------