diff --git a/CHANGELOG.md b/CHANGELOG.md index ef3c33f9cf..a8620508ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to `dash` will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [UNRELEASED] + +### Fixed +- [#4165](https://github.com/plotly/dash/pull/4165) Use `@pytest.hookimpl(tryfirst=True)` on `pytest_addhooks` in `dash.testing.plugin` to eliminate `PytestRemovedIn10Warning` during pytest plugin registration and preserve compatibility with pytest 10. Fixes [#2420](https://github.com/plotly/dash/issues/2420). + ## [4.5.1] - 2026-11-19 ### Removed diff --git a/dash/testing/plugin.py b/dash/testing/plugin.py index 1b917d7657..5146fc31a6 100644 --- a/dash/testing/plugin.py +++ b/dash/testing/plugin.py @@ -101,7 +101,7 @@ def pytest_addoption(parser): ) -@pytest.mark.tryfirst +@pytest.hookimpl(tryfirst=True) def pytest_addhooks(pluginmanager): if not _installed: return diff --git a/tests/unit/test_testing.py b/tests/unit/test_testing.py index b9c1cca344..b27a13bcad 100644 --- a/tests/unit/test_testing.py +++ b/tests/unit/test_testing.py @@ -1,7 +1,26 @@ -from dash.testing import ignore_register_page +import warnings + +import pluggy +import pytest + +from dash.testing import ignore_register_page, plugin from dash import register_page def test_tst001_ignore_register_page(): with ignore_register_page(): register_page("/") + + +def test_tst002_pytest_addhooks_uses_hookimpl(): + opts = pluggy.PluginManager("pytest").parse_hookimpl_opts(plugin, "pytest_addhooks") + assert opts is not None and opts.get("tryfirst") is True + + pm = pytest.PytestPluginManager() + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + pm.register(plugin, name="dash_testing_hookimpl_check") + pm.unregister(name="dash_testing_hookimpl_check") + + hook_warnings = [w for w in caught if "pytest_addhooks" in str(w.message)] + assert hook_warnings == []