Docs+Tests: clarify special discovery of pytest_generate_tests#13685
Docs+Tests: clarify special discovery of pytest_generate_tests#13685The-Compiler merged 6 commits intopytest-dev:mainfrom
Conversation
- Document that pytest_generate_tests is also discovered in test modules/classes. - Clarify other hooks must live in conftest.py or plugins; add cross-links. - Add a tiny pytester test demonstrating the behavior. - Pure docs/tests; no behavior change.
RonnyPfannschmidt
left a comment
There was a problem hiding this comment.
Nice enhancement, thanks
The-Compiler
left a comment
There was a problem hiding this comment.
The doc improvements make a lot of sense, but not a fan of having an entire new test file just for a single test.
Also the test seems redundant to me: That pytest_generate_tests can be invoked on a class is already covered in testing/python/metafunc.py in test_generate_tests_in_class, and that other hooks don't work there is somewhat covered by test_runtest_in_module_ordering in testing/test_runner.py (see the xfail and the comment above).
Thus I'd propose to delete the new test file and only keep the doc adjustments.
… pytest_generate_tests
Thanks 🙏 Just FYI: after separate feedback from The-Compiler I dropped the extra test and kept this as a docs-only PR. |
Thanks for the detailed review — agreed. I verified the existing coverage you pointed to:
I’ve dropped the redundant test file:
and kept this PR docs-only to clarify the special discovery rules of
Local checks re-run and passing (pre-commit / pytest / docs build). |
|
Thanks! |
Backport to 8.4.x: 💚 backport PR created✅ Backport PR branch: Backported as #13686 🤖 @patchback |
…-tests Docs+Tests: clarify special discovery of pytest_generate_tests (cherry picked from commit 12bde8a)
…2bde8af6dda3e7104f840209c199d151258b462/pr-13685 [PR #13685/12bde8af backport][8.4.x] Docs+Tests: clarify special discovery of pytest_generate_tests
|
Thanks! |
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