@@ -152,9 +152,10 @@ then the *hookimpl* should be marked with the ``"optionalhook"`` option:
152
152
153
153
Call time order
154
154
^^^^^^^^^^^^^^^
155
- A *hookimpl * can influence its call-time invocation position.
156
- If marked with a ``"tryfirst" `` or ``"trylast" `` option it will be
157
- executed *first * or *last * respectively in the hook call loop:
155
+ By default hooks are :ref: `called <calling >` in LIFO registered order, however,
156
+ a *hookimpl * can influence its call-time invocation position using special
157
+ attributes. If marked with a ``"tryfirst" `` or ``"trylast" `` option it
158
+ will be executed *first * or *last * respectively in the hook call loop:
158
159
159
160
.. code-block :: python
160
161
@@ -477,6 +478,8 @@ You can retrieve the *options* applied to a particular
477
478
http://doc.pytest.org/en/latest/writing_plugins.html#setuptools-entry-points
478
479
479
480
481
+ .. _calling :
482
+
480
483
Calling Hooks
481
484
*************
482
485
The core functionality of ``pluggy `` enables an extension provider
@@ -487,7 +490,7 @@ a :py:class:`pluggy._HookCaller` which in turn *loops* through the
487
490
``1:N `` registered *hookimpls * and calls them in sequence.
488
491
489
492
Every :py:class: `pluggy.PluginManager ` has a ``hook `` attribute
490
- which is an instance of a :py:class: `pluggy._HookRelay `.
493
+ which is an instance of this :py:class: `pluggy._HookRelay `.
491
494
The ``_HookRelay `` itself contains references (by hook name) to each
492
495
registered *hookimpl *'s ``_HookCaller `` instance.
493
496
@@ -510,6 +513,40 @@ More practically you call a *hook* like so:
510
513
511
514
Note that you **must ** call hooks using keyword `arguments `_ syntax!
512
515
516
+ Hook implementations are called in LIFO registered order: *the last
517
+ registered plugin's hooks are called first *. As an example, the below
518
+ assertion should not error:
519
+
520
+ .. code-block :: python
521
+
522
+ from pluggy import PluginManager, HookimplMarker
523
+
524
+ hookimpl = HookimplMarker(' myproject' )
525
+
526
+ class Plugin1 (object ):
527
+ def myhook (self , args ):
528
+ """ Default implementation.
529
+ """
530
+ return 1
531
+
532
+ class Plugin2 (object ):
533
+ def myhook (self , args ):
534
+ """ Default implementation.
535
+ """
536
+ return 2
537
+
538
+ class Plugin3 (object ):
539
+ def myhook (self , args ):
540
+ """ Default implementation.
541
+ """
542
+ return 3
543
+
544
+ pm = PluginManager(' myproject' )
545
+ pm.register(Plugin1())
546
+ pm.register(Plugin2())
547
+ pm.register(Plugin3())
548
+
549
+ assert pm.hook.myhook(args = ()) == [3 , 2 , 1 ]
513
550
514
551
Collecting results
515
552
------------------
0 commit comments