Skip to content

Commit 0cbf478

Browse files
committed
Merge branch 'main' into serializable
* main: Added check for pytest as test runner for IS_RUNNING_TESTS. (#2137) [pre-commit.ci] pre-commit autoupdate (#2140) Disabled document.cookie linter
2 parents bf77c70 + 46e2b91 commit 0cbf478

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
hooks:
1515
- id: doc8
1616
- repo: https://github.com/adamchainz/django-upgrade
17-
rev: 1.24.0
17+
rev: 1.25.0
1818
hooks:
1919
- id: django-upgrade
2020
args: [--target-version, "4.2"]
@@ -29,12 +29,12 @@ repos:
2929
- id: rst-backticks
3030
- id: rst-directive-colons
3131
- repo: https://github.com/biomejs/pre-commit
32-
rev: v2.0.0-beta.3
32+
rev: v2.0.0-beta.4
3333
hooks:
3434
- id: biome-check
3535
verbose: true
3636
- repo: https://github.com/astral-sh/ruff-pre-commit
37-
rev: 'v0.11.9'
37+
rev: 'v0.11.10'
3838
hooks:
3939
- id: ruff
4040
args: [--fix, --exit-non-zero-on-fix]

biome.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
"useExportType": "error",
3939
"noUselessElse": "error",
4040
"useShorthandFunctionType": "error"
41+
},
42+
"suspicious": {
43+
"noDocumentCookie": "off"
4144
}
4245
}
4346
},

debug_toolbar/settings.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
from django.dispatch import receiver
88
from django.test.signals import setting_changed
99

10+
11+
def _is_running_tests():
12+
"""
13+
Helper function to support testing default value for
14+
IS_RUNNING_TESTS
15+
"""
16+
return "test" in sys.argv or "PYTEST_VERSION" in os.environ
17+
18+
1019
CONFIG_DEFAULTS = {
1120
# Toolbar options
1221
"DISABLE_PANELS": {
@@ -45,7 +54,7 @@
4554
"OBSERVE_REQUEST_CALLBACK": "debug_toolbar.toolbar.observe_request",
4655
"TOOLBAR_LANGUAGE": None,
4756
"TOOLBAR_STORE_CLASS": "debug_toolbar.store.MemoryStore",
48-
"IS_RUNNING_TESTS": "test" in sys.argv or "PYTEST_VERSION" in os.environ,
57+
"IS_RUNNING_TESTS": _is_running_tests(),
4958
"UPDATE_ON_FETCH": False,
5059
}
5160

docs/spelling_wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ psycopg
4949
py
5050
pyflame
5151
pylibmc
52+
pytest
5253
pyupgrade
5354
querysets
5455
refactoring
@@ -65,5 +66,6 @@ theming
6566
timeline
6667
tox
6768
uWSGI
69+
unhandled
6870
unhashable
6971
validator

tests/test_settings.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from unittest.mock import patch
2+
3+
from django.test import TestCase
4+
5+
from debug_toolbar.settings import _is_running_tests
6+
7+
8+
class SettingsTestCase(TestCase):
9+
@patch("debug_toolbar.settings.sys")
10+
@patch("debug_toolbar.settings.os")
11+
def test_is_running_tests(self, mock_os, mock_sys):
12+
mock_sys.argv = "test"
13+
mock_os.environ = {}
14+
self.assertTrue(_is_running_tests())
15+
16+
mock_sys.argv = ""
17+
mock_os.environ = {}
18+
self.assertFalse(_is_running_tests())
19+
20+
mock_sys.argv = ""
21+
mock_os.environ = {"PYTEST_VERSION": "1"}
22+
self.assertTrue(_is_running_tests())

0 commit comments

Comments
 (0)