[PR #13685/12bde8af backport][8.4.x] Docs+Tests: clarify special discovery of pytest_generate_tests#13686
Merged
The-Compiler merged 1 commit into8.4.xfrom Aug 29, 2025
Conversation
…-tests Docs+Tests: clarify special discovery of pytest_generate_tests (cherry picked from commit 12bde8a)
The-Compiler
approved these changes
Aug 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.pyor plugins),pytest_generate_testsis 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_testsis 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.rstwith a clear note on the exception forpytest_generate_tests.doc/en/how-to/parametrize.rstwith a short reminder in the relevant section.testing/test_pytest_generate_tests_discovery.py, which demonstrates thatpytest_generate_testsinside a test module works, whilepytest_terminal_summarydoes not.Tests
pytest_generate_testsin 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