-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Docs+Tests: clarify special discovery of pytest_generate_tests #13685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs+Tests: clarify special discovery of pytest_generate_tests #13685
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice enhancement, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.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