From bbd3cff801a8122828e1bcf4242b605aced3c73b Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Tue, 29 Apr 2025 07:27:47 +0200 Subject: [PATCH 01/11] Add the GitHub release to the releasing process and remove the RTD notice, the default behavior is fine there --- docs/contributing.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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). From f00bfb667bf311c32db34e5e838b0b02e587012a Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Sat, 3 May 2025 00:46:48 -0500 Subject: [PATCH 02/11] Remove pin for django-csp. (#2132) * Remove pin for django-csp. The toolbar now supports django-csp v4 * Add django-template-partials to requirements file This allows make test to succeed again. --- requirements_dev.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 3d91e92592896ee090a27fc465d0e00be1c7fc1e Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 5 May 2025 08:23:59 +0200 Subject: [PATCH 03/11] Update the biome pre-commit hook now that biome doesn't crash on Django HTML templates anymore --- .pre-commit-config.yaml | 4 +-- biome.json | 36 ++++++++++++++++--- .../static/debug_toolbar/css/toolbar.css | 4 ++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 852048216..dc2a7b2e6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,12 +29,12 @@ repos: - id: rst-backticks - id: rst-directive-colons - repo: https://github.com/biomejs/pre-commit - rev: v1.9.4 + rev: v2.0.0-beta.2 hooks: - id: biome-check verbose: true - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.11.7' + rev: 'v0.11.8' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/biome.json b/biome.json index 625e4ebe7..5cf9a9c90 100644 --- a/biome.json +++ b/biome.json @@ -1,16 +1,44 @@ { - "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "$schema": "https://biomejs.dev/schemas/2.0.0-beta.2/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", + "useNumericLiterals": "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" + } } }, "javascript": { 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 { From fbceff0de2da81cab4a025cf7cbded345ef207cf Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 12 May 2025 08:02:56 +0200 Subject: [PATCH 04/11] Build docs on Ubuntu 24.04 --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From cf71ded725ddda6124e55762cc2115567d6eec4c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 May 2025 22:06:03 +0200 Subject: [PATCH 05/11] [pre-commit.ci] pre-commit autoupdate (#2135) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/biomejs/pre-commit: v2.0.0-beta.2 → v2.0.0-beta.3](https://github.com/biomejs/pre-commit/compare/v2.0.0-beta.2...v2.0.0-beta.3) - [github.com/astral-sh/ruff-pre-commit: v0.11.8 → v0.11.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.11.8...v0.11.9) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dc2a7b2e6..371824a6b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,12 +29,12 @@ repos: - id: rst-backticks - id: rst-directive-colons - repo: https://github.com/biomejs/pre-commit - rev: v2.0.0-beta.2 + rev: v2.0.0-beta.3 hooks: - id: biome-check verbose: true - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.11.8' + rev: 'v0.11.9' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 11c321f0670dcedd74423bf0407bc95c217f516d Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Fri, 16 May 2025 15:58:35 -0500 Subject: [PATCH 06/11] Disabled document.cookie linter The replacement, CookieStore isn't accessible on all browsers at this time, nor should we assume we always have access to secure environments. --- biome.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/biome.json b/biome.json index 5cf9a9c90..75ad07db8 100644 --- a/biome.json +++ b/biome.json @@ -38,6 +38,9 @@ "useExportType": "error", "noUselessElse": "error", "useShorthandFunctionType": "error" + }, + "suspicious": { + "noDocumentCookie": "off" } } }, From 7d68e0e7b61eb5133144c6f2cdb2d70c7b00d3a5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 May 2025 06:50:01 +0200 Subject: [PATCH 07/11] [pre-commit.ci] pre-commit autoupdate (#2140) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/adamchainz/django-upgrade: 1.24.0 → 1.25.0](https://github.com/adamchainz/django-upgrade/compare/1.24.0...1.25.0) - [github.com/biomejs/pre-commit: v2.0.0-beta.3 → v2.0.0-beta.4](https://github.com/biomejs/pre-commit/compare/v2.0.0-beta.3...v2.0.0-beta.4) - [github.com/astral-sh/ruff-pre-commit: v0.11.9 → v0.11.10](https://github.com/astral-sh/ruff-pre-commit/compare/v0.11.9...v0.11.10) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 371824a6b..c178042a1 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,12 +29,12 @@ repos: - id: rst-backticks - id: rst-directive-colons - repo: https://github.com/biomejs/pre-commit - rev: v2.0.0-beta.3 + rev: v2.0.0-beta.4 hooks: - id: biome-check verbose: true - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.11.9' + rev: 'v0.11.10' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 46e2b9183572d94a5695078efbaec0314556a82d Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Fri, 23 May 2025 03:00:01 -0500 Subject: [PATCH 08/11] Added check for pytest as test runner for IS_RUNNING_TESTS. (#2137) * Added check for pytest as test runner for IS_RUNNING_TESTS. * Move logic to determine IS_RUNNING_TESTS to a function This makes the logic testable. * Added words to spelling list for the changelog. --- debug_toolbar/settings.py | 12 +++++++++++- docs/changes.rst | 3 +++ docs/configuration.rst | 2 +- docs/installation.rst | 2 +- docs/spelling_wordlist.txt | 2 ++ tests/test_settings.py | 22 ++++++++++++++++++++++ 6 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/test_settings.py 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/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/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/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()) From 3fc0c05f15fb060c2132176339a9ec00d8f66c60 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 26 May 2025 20:03:53 +0000 Subject: [PATCH 09/11] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/biomejs/pre-commit: v2.0.0-beta.4 → v2.0.0-beta.5](https://github.com/biomejs/pre-commit/compare/v2.0.0-beta.4...v2.0.0-beta.5) - [github.com/astral-sh/ruff-pre-commit: v0.11.10 → v0.11.11](https://github.com/astral-sh/ruff-pre-commit/compare/v0.11.10...v0.11.11) - [github.com/tox-dev/pyproject-fmt: v2.5.1 → v2.6.0](https://github.com/tox-dev/pyproject-fmt/compare/v2.5.1...v2.6.0) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c178042a1..fae72da9c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,18 +29,18 @@ repos: - id: rst-backticks - id: rst-directive-colons - repo: https://github.com/biomejs/pre-commit - rev: v2.0.0-beta.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.10' + rev: 'v0.11.11' 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 From 5054a2382e124bc82e72abd347b0ce9f8b1c43d8 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Tue, 27 May 2025 07:47:59 +0200 Subject: [PATCH 10/11] Update the biome configuration --- biome.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/biome.json b/biome.json index 75ad07db8..dc2776d79 100644 --- a/biome.json +++ b/biome.json @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/2.0.0-beta.2/schema.json", + "$schema": "https://biomejs.dev/schemas/2.0.0-beta.5/schema.json", "formatter": { "enabled": true, "useEditorconfig": true @@ -20,7 +20,6 @@ "noCommaOperator": "error", "useNodejsImportProtocol": "error", "useAsConstAssertion": "error", - "useNumericLiterals": "error", "useEnumInitializers": "error", "useSelfClosingElements": "error", "useConst": "error", @@ -41,6 +40,9 @@ }, "suspicious": { "noDocumentCookie": "off" + }, + "complexity": { + "useNumericLiterals": "error" } } }, From c217334010fa54a8726640519ca29cb77fffda58 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Jun 2025 13:35:54 +0200 Subject: [PATCH 11/11] [pre-commit.ci] pre-commit autoupdate (#2142) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.11.11 → v0.11.12](https://github.com/astral-sh/ruff-pre-commit/compare/v0.11.11...v0.11.12) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fae72da9c..8c6115813 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,7 +34,7 @@ repos: - id: biome-check verbose: true - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.11.11' + rev: 'v0.11.12' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix]