Skip to content

Commit 357b3ea

Browse files
committed
Added check for pytest as test runner for IS_RUNNING_TESTS.
1 parent 11c321f commit 357b3ea

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

debug_toolbar/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23
import warnings
34
from functools import cache
@@ -43,7 +44,7 @@
4344
"SQL_WARNING_THRESHOLD": 500, # milliseconds
4445
"OBSERVE_REQUEST_CALLBACK": "debug_toolbar.toolbar.observe_request",
4546
"TOOLBAR_LANGUAGE": None,
46-
"IS_RUNNING_TESTS": "test" in sys.argv,
47+
"IS_RUNNING_TESTS": "test" in sys.argv or "PYTEST_VERSION" in os.environ,
4748
"UPDATE_ON_FETCH": False,
4849
}
4950

docs/changes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Change log
44
Pending
55
-------
66

7+
* Added support for checking if pytest as the test runner when determining
8+
if tests are running.
9+
710
5.2.0 (2025-04-29)
811
------------------
912

docs/configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Toolbar options
7777

7878
* ``IS_RUNNING_TESTS``
7979

80-
Default: ``"test" in sys.argv``
80+
Default: ``"test" in sys.argv or "PYTEST_VERSION" in os.environ``
8181

8282
This setting whether the application is running tests. If this resolves to
8383
``True``, the toolbar will prevent you from running tests. This should only

docs/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ can do this by adding another setting:
165165

166166
.. code-block:: python
167167
168-
TESTING = "test" in sys.argv
168+
TESTING = "test" in sys.argv or "PYTEST_VERSION" in os.environ
169169
170170
if not TESTING:
171171
INSTALLED_APPS = [

0 commit comments

Comments
 (0)