Skip to content

warn on ambiguous -p plugin module usage#14270

Open
kartikdp wants to merge 6 commits intopytest-dev:mainfrom
kartikdp:bugfix/pluginarg-invalid-entrypoint
Open

warn on ambiguous -p plugin module usage#14270
kartikdp wants to merge 6 commits intopytest-dev:mainfrom
kartikdp:bugfix/pluginarg-invalid-entrypoint

Conversation

@kartikdp
Copy link

@kartikdp kartikdp commented Mar 6, 2026

Summary

-p <name> can silently do the wrong thing with --disable-plugin-autoload
when <name> is an importable top-level module that has no pytest hooks,
while the real plugin is exposed via a pytest11 entry-point submodule.

This change adds a focused warning in that case:

  • if the imported module has no pytest hooks
  • and a pytest11 entry-point exists in one of its submodules
  • pytest emits PytestConfigWarning suggesting the entry-point name (for
    example -p recording)

closes #14135

Impact

This improves correctness and UX for plugin selection, especially in autoload-
disabled runs, by surfacing likely misconfiguration instead of failing
silently.

How tested

  • Added regression test:
    • testing/ test_config.py::test_disable_plugin_autoload_warns_for_submodule_entrypoint
  • Ran focused tests:
    • uv run -m pytest testing/test_config.py -k "disable_plugin_autoload_warns_for_submodule_entrypoint or test_disable_plugin_autoload"
    • uv run -m pytest testing/test_pluginmanager.py -k "import_plugin_importname or import_plugin_dotted_name"
  • Ran formatting/lint/hooks on changed files:
    • uv run --with pre-commit pre-commit run --files src/_pytest/config/ __init__.py testing/test_config.py changelog/14135.bugfix.rst

Checklist

  • Include documentation when adding new features. (Not applicable: bugfix,
    no new feature)
  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits.
  • Add text like closes #XYZW to PR description and/or commits.
  • If AI agents were used, they are credited in Co-authored-by commit
    trailers.
  • Create a new changelog file in the changelog directory.
  • Add yourself to AUTHORS in alphabetical order. (Not needed for this
    change)

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Mar 6, 2026
@kartikdp kartikdp force-pushed the bugfix/pluginarg-invalid-entrypoint branch from 4c67d0b to f0192b9 Compare March 6, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-p silently fails if parameter is an invalid plugin

1 participant