Skip to content

Commit 975a60a

Browse files
authored
Merge pull request #13686 from pytest-dev/patchback/backports/8.4.x/12bde8af6dda3e7104f840209c199d151258b462/pr-13685
[PR #13685/12bde8af backport][8.4.x] Docs+Tests: clarify special discovery of pytest_generate_tests
2 parents 2c94c4a + b7f0568 commit 975a60a

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

changelog/13577.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clarify that ``pytest_generate_tests`` is discovered in test modules/classes; other hooks must be in ``conftest.py`` or plugins.

doc/en/how-to/parametrize.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ command line option and the parametrization of our test function:
240240
if "stringinput" in metafunc.fixturenames:
241241
metafunc.parametrize("stringinput", metafunc.config.getoption("stringinput"))
242242
243+
.. note::
244+
245+
The :hook:`pytest_generate_tests` hook can also be implemented directly in a test
246+
module or inside a test class; unlike other hooks, pytest will discover it there
247+
as well. Other hooks must live in a :ref:`conftest.py <localplugin>` or a plugin.
248+
See :ref:`writinghooks`.
249+
243250
If we now pass two stringinput values, our test will run twice:
244251

245252
.. code-block:: pytest

doc/en/how-to/writing_hook_functions.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ Example:
235235
"""
236236
print(config.hook)
237237
238+
.. note::
239+
240+
Unlike other hooks, the :hook:`pytest_generate_tests` hook is also discovered when
241+
defined inside a test module or test class. Other hooks must live in
242+
:ref:`conftest.py plugins <localplugin>` or external plugins.
243+
See :ref:`parametrize-basics` and the :ref:`hook-reference`.
238244

239245
.. _`addoptionhooks`:
240246

0 commit comments

Comments
 (0)