Skip to content

manager: deprecate register(None) - #791

Closed
MbappeWU wants to merge 1 commit into
pytest-dev:mainfrom
MbappeWU:deprecate-register-none
Closed

MbappeWU wants to merge 1 commit into
pytest-dev:mainfrom
MbappeWU:deprecate-register-none

Conversation

@MbappeWU

Copy link
Copy Markdown

Fixes #790.

Problem

Since #752, PluginManager.register(None) is silently ignored (it used to misbehave, #731, and raising broke devpi's tests, #749). In #749 the follow-up agreed was to add a deprecation warning so callers can migrate before None becomes an error.

Change

  • register(None) still returns None and registers nothing, but now emits a DeprecationWarning with stacklevel=2, so the warning points at the caller's register() line:

    Passing None to PluginManager.register() is deprecated and will become an error in a future version; it is currently ignored.

  • The register docstring mentions the deprecation.

  • test_register_ignores_none asserts the warning (message, a single record, and that it is attributed to the calling file) in addition to the existing "ignored" assertions.

  • Towncrier fragment changelog/790.removal.rst ("Deprecations and Removals").

I used a plain DeprecationWarning, as the hookspec-without-self deprecation does. Happy to switch to a PluggyWarning subclass if you prefer a pluggy-specific category.

Verification

  • uv run pytest: 219 passed.
  • With the _manager.py change reverted, the updated test fails: Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>,) were emitted.
  • uv run pre-commit run on the changed files: ruff check/format, autoflake, pyupgrade, blacken-docs and mypy all pass.

Passing None to PluginManager.register() is silently ignored since pytest-dev#752.
Emit a DeprecationWarning (pointing at the caller) so users can migrate
before it becomes an error in a future version.

Fixes pytest-dev#790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deprecate passing None as a plugin instance

2 participants