[PR #13685/12bde8af backport][8.4.x] Docs+Tests: clarify special discovery of pytest_generate_tests #13686
+14
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a backport of PR #13685 as merged into main (12bde8a).
Summary
This PR improves the documentation and tests around the special discovery rules of
pytest_generate_tests
. Unlike most hooks (which must live inconftest.py
or plugins),pytest_generate_tests
is also discovered when defined directly inside test modules or classes. This PR clarifies that behavior in the docs and adds a minimal self-test that shows the difference.Motivation
New users often get confused about where hooks should be placed. By explicitly pointing out that
pytest_generate_tests
is the only exception to the “hooks go in conftest/plugins” rule, we reduce misunderstandings and make the docs easier to follow.Changes
doc/en/how-to/writing_hook_functions.rst
with a clear note on the exception forpytest_generate_tests
.doc/en/how-to/parametrize.rst
with a short reminder in the relevant section.testing/test_pytest_generate_tests_discovery.py
, which demonstrates thatpytest_generate_tests
inside a test module works, whilepytest_terminal_summary
does not.Tests
pytest_generate_tests
in a test module parametrizes correctly.pytest_terminal_summary
) inside a test module is ignored.Docs
Only minimal “Note:” additions with cross-links, written for clarity and easy review.
Notes
No behavior changes — purely docs and tests. Pre-commit, mypy, and docs build all pass locally.
Related Issue
Closes #13577