From c5a7ae8ad1e31588cd30ecce5bbc9c7faaf3f32e Mon Sep 17 00:00:00 2001 From: CortexShadow Date: Sat, 6 Jun 2026 14:01:45 +0330 Subject: [PATCH] Clarify conftest hook timing --- changelog/14557.doc.rst | 1 + doc/en/how-to/writing_plugins.rst | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 changelog/14557.doc.rst diff --git a/changelog/14557.doc.rst b/changelog/14557.doc.rst new file mode 100644 index 00000000000..38d10046375 --- /dev/null +++ b/changelog/14557.doc.rst @@ -0,0 +1 @@ +Clarified that conftest files discovered during collection are not available for hooks which run before collection, such as :hook:`pytest_sessionstart` and :hook:`pytest_report_header`. diff --git a/doc/en/how-to/writing_plugins.rst b/doc/en/how-to/writing_plugins.rst index 56043a14f97..386eb8f5f65 100644 --- a/doc/en/how-to/writing_plugins.rst +++ b/doc/en/how-to/writing_plugins.rst @@ -59,6 +59,11 @@ Plugin discovery order at tool startup After a ``conftest.py`` file is loaded, recursively load all plugins specified in its :globalvar:`pytest_plugins` variable if present. + These initial conftest files are loaded before collection starts. Conftest + files discovered later during collection can still implement hooks, but they + are not available for hooks which run before collection, such as + :hook:`pytest_sessionstart` and :hook:`pytest_report_header`. + .. _`conftest.py plugins`: .. _`localplugin`: