File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change
1
+ Clarify that ``pytest_generate_tests `` is discovered in test modules/classes; other hooks must be in ``conftest.py `` or plugins.
Original file line number Diff line number Diff line change @@ -240,6 +240,13 @@ command line option and the parametrization of our test function:
240
240
if " stringinput" in metafunc.fixturenames:
241
241
metafunc.parametrize(" stringinput" , metafunc.config.getoption(" stringinput" ))
242
242
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
+
243
250
If we now pass two stringinput values, our test will run twice:
244
251
245
252
.. code-block :: pytest
Original file line number Diff line number Diff line change @@ -235,6 +235,12 @@ Example:
235
235
"""
236
236
print (config.hook)
237
237
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 `.
238
244
239
245
.. _`addoptionhooks` :
240
246
You can’t perform that action at this time.
0 commit comments