Skip to content

Commit 4cfa3a5

Browse files
author
Tyler Goodlet
committed
Document the public _Result API methods
Resolves #49
1 parent 428ab80 commit 4cfa3a5

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

docs/api_reference.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ Api Reference
55
:members:
66
:undoc-members:
77
:show-inheritance:
8+
9+
10+
.. automethod:: pluggy._Result.get_result
11+
12+
.. automethod:: pluggy._Result.force_result
13+
14+
.. automethod:: pluggy._HookCaller.call_extra

docs/index.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ Wrappers
202202
A *hookimpl* can be marked with a ``"hookwrapper"`` option which indicates that
203203
the function will be called to *wrap* (or surround) all other normal *hookimpl*
204204
calls. A *hookwrapper* can thus execute some code ahead and after the execution
205-
of all corresponding non-hookwrappper *hookimpls*.
205+
of all corresponding non-wrappper *hookimpls*.
206206

207207
Much in the same way as a `@contextlib.contextmanager`_, *hookwrappers* must
208208
be implemented as generator function with a single ``yield`` in its body:
@@ -235,13 +235,15 @@ be implemented as generator function with a single ``yield`` in its body:
235235
if config.use_defaults:
236236
outcome.force_result(defaults)
237237
238-
The generator is `sent`_ a :py:class:`pluggy._CallOutcome` object which can
238+
The generator is `sent`_ a :py:class:`pluggy._Result` object which can
239239
be assigned in the ``yield`` expression and used to override or inspect
240-
the final result(s) returned back to the hook caller.
240+
the final result(s) returned back to the caller using the
241+
:py:meth:`~pluggy._Result.force_result` or
242+
:py:meth:`~pluggy._Result.get_result` methods.
241243

242244
.. note::
243245
Hook wrappers can **not** return results (as per generator function
244-
semantics); they can only modify them using the ``_CallOutcome`` API.
246+
semantics); they can only modify them using the ``_Result`` API.
245247

246248
Also see the `hookwrapper`_ section in the ``pytest`` docs.
247249

@@ -599,7 +601,7 @@ Calling with a subset of registered plugins
599601
-------------------------------------------
600602
You can make a call using a subset of plugins by asking the
601603
``PluginManager`` first for a ``_HookCaller`` with those plugins removed
602-
using the :py:meth:`pluggy.PluginManger.subset_hook_caller()` method.
604+
using the :py:meth:`pluggy.PluginManager.subset_hook_caller()` method.
603605

604606
You then can use that ``_HookCaller`` to make normal, ``call_historic()``,
605607
or ``call_extra()`` calls as necessary.

pluggy/callers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,21 @@ def from_call(cls, func):
4141
return cls(result, excinfo)
4242

4343
def force_result(self, result):
44+
"""Force the result(s) to ``result``.
45+
46+
If the hook was marked as a ``firstresult`` a single value should
47+
be set otherwise set a (modified) list of results. Any exceptions
48+
found during invocation will be deleted.
49+
"""
4450
self.result = result
4551
self.excinfo = None
4652

4753
def get_result(self):
54+
"""Get the result(s) for this hook call.
55+
56+
If the hook was marked as a ``firstresult`` only a single value
57+
will be returned otherwise a list of results.
58+
"""
4859
__tracebackhide__ = True
4960
if self.excinfo is None:
5061
return self.result

0 commit comments

Comments
 (0)