Skip to content

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Aug 29, 2025

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 in conftest.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

  • Updated doc/en/how-to/writing_hook_functions.rst with a clear note on the exception for pytest_generate_tests.
  • Updated doc/en/how-to/parametrize.rst with a short reminder in the relevant section.
  • Added testing/test_pytest_generate_tests_discovery.py, which demonstrates that pytest_generate_tests inside a test module works, while pytest_terminal_summary does not.

Tests

  • Confirms pytest_generate_tests in a test module parametrizes correctly.
  • Confirms another hook (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

…-tests

Docs+Tests: clarify special discovery of pytest_generate_tests

(cherry picked from commit 12bde8a)
@The-Compiler The-Compiler enabled auto-merge August 29, 2025 23:04
@The-Compiler The-Compiler merged commit 975a60a into 8.4.x Aug 29, 2025
36 checks passed
@The-Compiler The-Compiler deleted the patchback/backports/8.4.x/12bde8af6dda3e7104f840209c199d151258b462/pr-13685 branch August 29, 2025 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant