pytest icon indicating copy to clipboard operation
pytest copied to clipboard

doc: Clarify conftest.py hooks unavailable during pytest_addoption

Open FazeelUsmani opened this issue 1 month ago • 3 comments

Fixes #13304

The documentation in "Writing hook functions" incorrectly suggested that hook implementations in conftest.py files are accessible during pytest_addoption() execution. This led to confusion when developers tried to use conftest hooks to provide default values for plugin options.

Changes

  • Updated the example in the "Using hooks in pytest_addoption" section to show a third-party plugin instead of a conftest.py file
  • Added a clear warning note explaining that conftest.py hooks are not available during pytest_addoption() because conftest files are discovered and loaded after plugin initialization
  • Documented which plugin types ARE available during pytest_addoption():
    • builtin plugins
    • plugins explicitly loaded with -p on the command line
    • installed third-party plugins (via setuptools entry points)
    • plugins specified via the PYTEST_PLUGINS environment variable
  • Added cross-reference to the plugin discovery order documentation

Testing

  • Documentation-only change, no code behavior modified
  • Verified RST syntax is correct
  • Confirmed all cross-references are valid
  • Changelog entry created: changelog/13304.doc.rst

FazeelUsmani avatar Nov 12 '25 13:11 FazeelUsmani