summaryrefslogtreecommitdiff
path: root/doc/en/writing_plugins.rst
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2019-04-14 23:22:21 +0200
committerDaniel Hahler <git@thequod.de>2019-04-14 23:22:21 +0200
commit6f0a5789fb5e16f9183b854658506a1702a92dad (patch)
tree6492fb7283588f1cff5efdae5d8f73e664f6af1b /doc/en/writing_plugins.rst
parent19035f4b552c3164d4d7a10fbc6113b47232a99d (diff)
parent533e610a35e05a2223294b39fb8a2fdd7d983f78 (diff)
downloadpytest-6f0a5789fb5e16f9183b854658506a1702a92dad.tar.gz
Merge master into features
Diffstat (limited to 'doc/en/writing_plugins.rst')
-rw-r--r--doc/en/writing_plugins.rst13
1 files changed, 10 insertions, 3 deletions
diff --git a/doc/en/writing_plugins.rst b/doc/en/writing_plugins.rst
index e717431e6..ec0e96198 100644
--- a/doc/en/writing_plugins.rst
+++ b/doc/en/writing_plugins.rst
@@ -528,10 +528,13 @@ a :py:class:`Result <pluggy._Result>` instance which encapsulates a result or
exception info. The yield point itself will thus typically not raise
exceptions (unless there are bugs).
-Here is an example definition of a hook wrapper::
+Here is an example definition of a hook wrapper:
+
+.. code-block:: python
import pytest
+
@pytest.hookimpl(hookwrapper=True)
def pytest_pyfunc_call(pyfuncitem):
do_something_before_next_hook_executes()
@@ -636,10 +639,13 @@ if you depend on a plugin that is not installed, validation will fail and
the error message will not make much sense to your users.
One approach is to defer the hook implementation to a new plugin instead of
-declaring the hook functions directly in your plugin module, for example::
+declaring the hook functions directly in your plugin module, for example:
+
+.. code-block:: python
# contents of myplugin.py
+
class DeferPlugin(object):
"""Simple plugin to defer pytest-xdist hook functions."""
@@ -647,8 +653,9 @@ declaring the hook functions directly in your plugin module, for example::
"""standard xdist hook function.
"""
+
def pytest_configure(config):
- if config.pluginmanager.hasplugin('xdist'):
+ if config.pluginmanager.hasplugin("xdist"):
config.pluginmanager.register(DeferPlugin())
This has the added benefit of allowing you to conditionally install hooks