From 14d6d8ab6b1873a2a38830ae5b035c8e6c17871a Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 27 May 2024 10:35:42 +0200 Subject: [PATCH 1/4] Add a section to the installation docs about running tests Fixes #1920. I thought about including the relevant documentation in the earlier steps, but I'd have to explain DEBUG, INTERNAL_IPS and TESTING all at once instead of introducing everything step by step. So even though it may be annoying to go back and modify code the user just added it still reads better to me, especially since it only applies to users running tests in their project. (I would hope a lot of them do, but still.) --- docs/installation.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/installation.rst b/docs/installation.rst index 3644bdd5c..ce2e8652a 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -156,6 +156,30 @@ 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 = "argv" 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")), + ] + + Troubleshooting --------------- From 44ae98d9a04bb7dd7d0b8d1f0387c65ef418fe68 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 27 May 2024 10:53:25 +0200 Subject: [PATCH 2/4] Fix formatting issues --- docs/configuration.rst | 2 ++ docs/installation.rst | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) 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 ce2e8652a..aa447cd5c 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -159,15 +159,22 @@ option. 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: +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 = "argv" in sys.argv if not TESTING: - INSTALLED_APPS = [*INSTALLED_APPS, "debug_toolbar"] - MIDDLEWARE = ["debug_toolbar.middleware.DebugToolbarMiddleware", *MIDDLEWARE] + INSTALLED_APPS = [ + *INSTALLED_APPS, + "debug_toolbar", + ] + MIDDLEWARE = [ + "debug_toolbar.middleware.DebugToolbarMiddleware", + *MIDDLEWARE, + ] You should also modify your URLconf file: @@ -179,6 +186,8 @@ You should also modify your URLconf file: path("__debug__/", include("debug_toolbar.urls")), ] +Alternatively, you can check out the :ref:`IS_RUNNING_TESTS ` +option. Troubleshooting --------------- From 17e18e591d4f7c1446b4d4d375067e6e6ddd596d Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 27 May 2024 11:00:13 +0200 Subject: [PATCH 3/4] Fix a typo --- docs/installation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installation.rst b/docs/installation.rst index aa447cd5c..657450fac 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -164,7 +164,7 @@ can do this by adding another setting: .. code-block:: python - TESTING = "argv" in sys.argv + TESTING = "test" in sys.argv if not TESTING: INSTALLED_APPS = [ From 0b2c1a61daa6a4a603703aa0654fec3aa2d5f2f8 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 27 May 2024 12:49:31 +0200 Subject: [PATCH 4/4] Add a changelog entry --- docs/changes.rst | 2 ++ 1 file changed, 2 insertions(+) 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)