Skip to content

Commit 16c52f0

Browse files
authored
Merge pull request #3177 from nicoddemus/mention-force-result
Mention outcome.force_result() and add link to pluggy's docs
2 parents f721829 + 653abad commit 16c52f0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

doc/en/writing_plugins.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,19 +462,24 @@ Here is an example definition of a hook wrapper::
462462

463463
@pytest.hookimpl(hookwrapper=True)
464464
def pytest_pyfunc_call(pyfuncitem):
465-
# do whatever you want before the next hook executes
465+
do_something_before_next_hook_executes()
466466

467467
outcome = yield
468468
# outcome.excinfo may be None or a (cls, val, tb) tuple
469469

470470
res = outcome.get_result() # will raise if outcome was exception
471-
# postprocess result
471+
472+
post_process_result(res)
473+
474+
outcome.force_result(new_res) # to override the return value to the plugin system
472475

473476
Note that hook wrappers don't return results themselves, they merely
474477
perform tracing or other side effects around the actual hook implementations.
475478
If the result of the underlying hook is a mutable object, they may modify
476479
that result but it's probably better to avoid it.
477480

481+
For more information, consult the `pluggy documentation <http://pluggy.readthedocs.io/en/latest/#wrappers>`_.
482+
478483

479484
Hook function ordering / call example
480485
-------------------------------------

0 commit comments

Comments
 (0)