diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 852048216..8c6115813 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: hooks: - id: doc8 - repo: https://github.com/adamchainz/django-upgrade - rev: 1.24.0 + rev: 1.25.0 hooks: - id: django-upgrade args: [--target-version, "4.2"] @@ -29,18 +29,18 @@ repos: - id: rst-backticks - id: rst-directive-colons - repo: https://github.com/biomejs/pre-commit - rev: v1.9.4 + rev: v2.0.0-beta.5 hooks: - id: biome-check verbose: true - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.11.7' + rev: 'v0.11.12' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - id: ruff-format - repo: https://github.com/tox-dev/pyproject-fmt - rev: v2.5.1 + rev: v2.6.0 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 5843d0212..794f8b3ed 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -5,7 +5,7 @@ version: 2 build: - os: ubuntu-22.04 + os: ubuntu-24.04 tools: python: "3.10" diff --git a/biome.json b/biome.json index 625e4ebe7..dc2776d79 100644 --- a/biome.json +++ b/biome.json @@ -1,16 +1,49 @@ { - "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "$schema": "https://biomejs.dev/schemas/2.0.0-beta.5/schema.json", "formatter": { "enabled": true, "useEditorconfig": true }, - "organizeImports": { - "enabled": true + "assist": { + "actions": { + "source": { + "organizeImports": "on" + } + } }, "linter": { "enabled": true, "rules": { - "recommended": true + "recommended": true, + "style": { + "useLiteralEnumMembers": "error", + "noCommaOperator": "error", + "useNodejsImportProtocol": "error", + "useAsConstAssertion": "error", + "useEnumInitializers": "error", + "useSelfClosingElements": "error", + "useConst": "error", + "useSingleVarDeclarator": "error", + "noUnusedTemplateLiteral": "error", + "useNumberNamespace": "error", + "noInferrableTypes": "error", + "useExponentiationOperator": "error", + "useTemplate": "error", + "noParameterAssign": "error", + "noNonNullAssertion": "error", + "useDefaultParameterLast": "error", + "noArguments": "error", + "useImportType": "error", + "useExportType": "error", + "noUselessElse": "error", + "useShorthandFunctionType": "error" + }, + "suspicious": { + "noDocumentCookie": "off" + }, + "complexity": { + "useNumericLiterals": "error" + } } }, "javascript": { diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index 59d538a0b..4dc801c2c 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -1,3 +1,4 @@ +import os import sys import warnings from functools import cache @@ -6,6 +7,15 @@ from django.dispatch import receiver from django.test.signals import setting_changed + +def _is_running_tests(): + """ + Helper function to support testing default value for + IS_RUNNING_TESTS + """ + return "test" in sys.argv or "PYTEST_VERSION" in os.environ + + CONFIG_DEFAULTS = { # Toolbar options "DISABLE_PANELS": { @@ -43,7 +53,7 @@ "SQL_WARNING_THRESHOLD": 500, # milliseconds "OBSERVE_REQUEST_CALLBACK": "debug_toolbar.toolbar.observe_request", "TOOLBAR_LANGUAGE": None, - "IS_RUNNING_TESTS": "test" in sys.argv, + "IS_RUNNING_TESTS": _is_running_tests(), "UPDATE_ON_FETCH": False, } diff --git a/debug_toolbar/static/debug_toolbar/css/toolbar.css b/debug_toolbar/static/debug_toolbar/css/toolbar.css index f147bcdff..3a8d5628f 100644 --- a/debug_toolbar/static/debug_toolbar/css/toolbar.css +++ b/debug_toolbar/static/debug_toolbar/css/toolbar.css @@ -170,7 +170,9 @@ #djDebug button:active { border: 1px solid #aaa; border-bottom: 1px solid #888; - box-shadow: inset 0 0 5px 2px #aaa, 0 1px 0 0 #eee; + box-shadow: + inset 0 0 5px 2px #aaa, + 0 1px 0 0 #eee; } #djDebug #djDebugToolbar { diff --git a/docs/changes.rst b/docs/changes.rst index bf1998de8..6d6f34b2d 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,6 +4,9 @@ Change log Pending ------- +* Added support for checking if pytest as the test runner when determining + if tests are running. + 5.2.0 (2025-04-29) ------------------ diff --git a/docs/configuration.rst b/docs/configuration.rst index d9e7ff342..377c97da8 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -77,7 +77,7 @@ Toolbar options * ``IS_RUNNING_TESTS`` - Default: ``"test" in sys.argv`` + Default: ``"test" in sys.argv or "PYTEST_VERSION" in os.environ`` This setting whether the application is running tests. If this resolves to ``True``, the toolbar will prevent you from running tests. This should only diff --git a/docs/contributing.rst b/docs/contributing.rst index 4d690c954..1ab7077aa 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -199,7 +199,8 @@ The release itself requires the following steps: #. Push the commit and the tag. -#. Publish the release from the Django Commons website. +#. Publish the release from the GitHub actions workflow. -#. Change the default version of the docs to point to the latest release: - https://readthedocs.org/dashboard/django-debug-toolbar/versions/ +#. **After the publishing completed** edit the automatically created GitHub + release to include the release notes (you may use GitHub's "Generate release + notes" button for this). diff --git a/docs/installation.rst b/docs/installation.rst index 61187570d..b89a2f563 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -165,7 +165,7 @@ can do this by adding another setting: .. code-block:: python - TESTING = "test" in sys.argv + TESTING = "test" in sys.argv or "PYTEST_VERSION" in os.environ if not TESTING: INSTALLED_APPS = [ diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt index 0f58c1f52..79b05cb06 100644 --- a/docs/spelling_wordlist.txt +++ b/docs/spelling_wordlist.txt @@ -49,6 +49,7 @@ psycopg py pyflame pylibmc +pytest pyupgrade querysets refactoring @@ -65,5 +66,6 @@ theming timeline tox uWSGI +unhandled unhashable validator diff --git a/requirements_dev.txt b/requirements_dev.txt index 941e74a81..6915226fd 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -11,7 +11,8 @@ html5lib selenium tox black -django-csp<4 # Used in tests/test_csp_rendering +django-template-partials +django-csp # Used in tests/test_csp_rendering # Integration support diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 000000000..f7dc676b1 --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,22 @@ +from unittest.mock import patch + +from django.test import TestCase + +from debug_toolbar.settings import _is_running_tests + + +class SettingsTestCase(TestCase): + @patch("debug_toolbar.settings.sys") + @patch("debug_toolbar.settings.os") + def test_is_running_tests(self, mock_os, mock_sys): + mock_sys.argv = "test" + mock_os.environ = {} + self.assertTrue(_is_running_tests()) + + mock_sys.argv = "" + mock_os.environ = {} + self.assertFalse(_is_running_tests()) + + mock_sys.argv = "" + mock_os.environ = {"PYTEST_VERSION": "1"} + self.assertTrue(_is_running_tests())