Skip to content

Fix pytest_addhooks deprecated tryfirst marker - #4165

Open
M-Colley wants to merge 2 commits into
plotly:devfrom
M-Colley:fix/pytest-addhooks-hookimpl
Open

M-Colley wants to merge 2 commits into
plotly:devfrom
M-Colley:fix/pytest-addhooks-hookimpl

Conversation

@M-Colley

Copy link
Copy Markdown
Contributor

Replace the deprecated @pytest.mark.tryfirst marker on pytest_addhooks in dash/testing/plugin.py with @pytest.hookimpl(tryfirst=True).

Problem and behavior

Pytest deprecated configuring hook implementations via @pytest.mark.* in pytest 7.2 (PytestRemovedIn10Warning: The hookimpl pytest_addhooks uses old-style configuration options (marks or attributes)) and removes support in pytest 10. Because dash.testing.plugin is registered via the pytest11 entry point, any test suite running in an environment with dash installed receives this warning on startup and fails under -W error or pytest 10.

Fixes #2420

Validation

  • Baseline reproduction: registering dash.testing.plugin on pytest.PytestPluginManager() emitted PytestRemovedIn10Warning.
  • Patched verification (Windows 11, Python 3.12.7, pytest 9.2.0, pluggy 1.7.0):
    pytest -p no:dash -p dash.testing.plugin -W error::pytest.PytestRemovedIn10Warning tests/unit/test_testing.py -v (2 passed).
  • Formatting & lint: black --check and flake8 --config .flake8 on dash/testing/plugin.py and tests/unit/test_testing.py.

Contributor Checklist

  • This PR targets dev (fix or chore) or next (feature, new API, breaking change), see Which branch to target
  • I have broken down my PR scope into the following TODO tasks
    • Replace @pytest.mark.tryfirst with @pytest.hookimpl(tryfirst=True) on pytest_addhooks
    • Add unit regression test_tst002_pytest_addhooks_uses_hookimpl and CHANGELOG.md entry
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PytestDeprecationWarning: The hookimpl pytest_addhooks uses old-style configuration options

1 participant