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()