From ac01075139c76096d88a86648804560582fd339e Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 17 Sep 2026 13:21:16 +0300 Subject: [PATCH] fixtures: change `--fixtures`/`--fixtures-per-test` to call `pytest_collection` hook instead of collecting directly I don't see a reason for these two commands to bypass the regular collection. If plugins do things with the hook on a regular run, they should do it for these two modes as well, just as they do with `--collect-only`. --- changelog/15049.breaking.rst | 2 ++ src/_pytest/fixtures.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelog/15049.breaking.rst diff --git a/changelog/15049.breaking.rst b/changelog/15049.breaking.rst new file mode 100644 index 00000000000..f6da93ddc7c --- /dev/null +++ b/changelog/15049.breaking.rst @@ -0,0 +1,2 @@ +When :option:`--fixtures` or :option:`--fixtures-per-test` are used, the :hook:`pytest_collection` hook is now called to perform the collection. +Previously, these two modes performed the collection directly, bypassing the hook. diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 7656fca2f5b..d4a1b9b6221 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -2450,7 +2450,8 @@ def _get_fixtures_per_test(test: nodes.Item) -> Iterator[FixtureDef[object]]: def _show_fixtures_per_test(config: Config, session: Session) -> None: import _pytest.config - session.perform_collect() + config.hook.pytest_collection(session=session) + invocation_dir = config.invocation_params.dir tw = _pytest.config.create_terminal_writer(config) verbose = config.get_verbosity() @@ -2505,7 +2506,8 @@ def showfixtures(config: Config) -> int | ExitCode: def _showfixtures_main(config: Config, session: Session) -> None: import _pytest.config - session.perform_collect() + config.hook.pytest_collection(session=session) + invocation_dir = config.invocation_params.dir tw = _pytest.config.create_terminal_writer(config) verbose = config.get_verbosity()