Skip to content

Commit f7e83b1

Browse files
authored
Add a section to the installation docs about running tests (#1921)
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.)
1 parent 782bdd9 commit f7e83b1

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

docs/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Pending
66

77
* Removed some CSS which wasn't carefully limited to the toolbar's elements.
88
* Stopped assuming that ``INTERNAL_IPS`` is a list.
9+
* Added a section to the installation docs about running tests in projects
10+
where the toolbar is being used.
911

1012

1113
4.4.1 (2024-05-26)

docs/configuration.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Toolbar options
7272
The toolbar searches for this string in the HTML and inserts itself just
7373
before.
7474

75+
.. _IS_RUNNING_TESTS:
76+
7577
* ``IS_RUNNING_TESTS``
7678

7779
Default: ``"test" in sys.argv``

docs/installation.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,39 @@ option.
156156
able to get the toolbar to work with your docker installation, review
157157
the code in ``debug_toolbar.middleware.show_toolbar``.
158158

159+
7. Disable the toolbar when running tests (optional)
160+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
161+
162+
If you're running tests in your project you shouldn't activate the toolbar. You
163+
can do this by adding another setting:
164+
165+
.. code-block:: python
166+
167+
TESTING = "test" in sys.argv
168+
169+
if not TESTING:
170+
INSTALLED_APPS = [
171+
*INSTALLED_APPS,
172+
"debug_toolbar",
173+
]
174+
MIDDLEWARE = [
175+
"debug_toolbar.middleware.DebugToolbarMiddleware",
176+
*MIDDLEWARE,
177+
]
178+
179+
You should also modify your URLconf file:
180+
181+
.. code-block:: python
182+
183+
if not settings.TESTING:
184+
urlpatterns = [
185+
*urlpatterns,
186+
path("__debug__/", include("debug_toolbar.urls")),
187+
]
188+
189+
Alternatively, you can check out the :ref:`IS_RUNNING_TESTS <IS_RUNNING_TESTS>`
190+
option.
191+
159192
Troubleshooting
160193
---------------
161194

0 commit comments

Comments
 (0)