Skip to content

Commit d3f47bf

Browse files
kamahmadnicoddemus
andauthored
Improved 'Declaring new hooks' section in docs. (#7782)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
1 parent 3db2489 commit d3f47bf

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Joshua Bronson
151151
Jurko Gospodnetić
152152
Justyna Janczyszyn
153153
Kale Kundert
154+
Kamran Ahmad
154155
Karl O. Pinc
155156
Katarzyna Jachim
156157
Katarzyna Król

doc/en/writing_plugins.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,11 @@ among each other.
614614
Declaring new hooks
615615
------------------------
616616

617+
.. note::
618+
619+
This is a quick overview on how to add new hooks and how they work in general, but a more complete
620+
overview can be found in `the pluggy documentation <https://pluggy.readthedocs.io/en/latest/>`__.
621+
617622
.. currentmodule:: _pytest.hookspec
618623

619624
Plugins and ``conftest.py`` files may declare new hooks that can then be
@@ -627,7 +632,7 @@ Hooks are usually declared as do-nothing functions that contain only
627632
documentation describing when the hook will be called and what return values
628633
are expected. The names of the functions must start with `pytest_` otherwise pytest won't recognize them.
629634

630-
Here's an example. Let's assume this code is in the ``hooks.py`` module.
635+
Here's an example. Let's assume this code is in the ``sample_hook.py`` module.
631636

632637
.. code-block:: python
633638
@@ -643,10 +648,10 @@ class or module can then be passed to the ``pluginmanager`` using the ``pytest_a
643648
.. code-block:: python
644649
645650
def pytest_addhooks(pluginmanager):
646-
""" This example assumes the hooks are grouped in the 'hooks' module. """
647-
from my_app.tests import hooks
651+
""" This example assumes the hooks are grouped in the 'sample_hook' module. """
652+
from my_app.tests import sample_hook
648653
649-
pluginmanager.add_hookspecs(hooks)
654+
pluginmanager.add_hookspecs(sample_hook)
650655
651656
For a real world example, see `newhooks.py`_ from `xdist <https://github.com/pytest-dev/pytest-xdist>`_.
652657

0 commit comments

Comments
 (0)