Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/13577.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarify that ``pytest_generate_tests`` is discovered in test modules/classes; other hooks must be in ``conftest.py`` or plugins.
7 changes: 7 additions & 0 deletions doc/en/how-to/parametrize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ command line option and the parametrization of our test function:
if "stringinput" in metafunc.fixturenames:
metafunc.parametrize("stringinput", metafunc.config.getoption("stringinput"))
.. note::

The :hook:`pytest_generate_tests` hook can also be implemented directly in a test
module or inside a test class; unlike other hooks, pytest will discover it there
as well. Other hooks must live in a :ref:`conftest.py <localplugin>` or a plugin.
See :ref:`writinghooks`.

If we now pass two stringinput values, our test will run twice:

.. code-block:: pytest
Expand Down
6 changes: 6 additions & 0 deletions doc/en/how-to/writing_hook_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ Example:
"""
print(config.hook)

.. note::

Unlike other hooks, the :hook:`pytest_generate_tests` hook is also discovered when
defined inside a test module or test class. Other hooks must live in
:ref:`conftest.py plugins <localplugin>` or external plugins.
See :ref:`parametrize-basics` and the :ref:`hook-reference`.

.. _`addoptionhooks`:

Expand Down
Loading