2010-11-06 06:37:31 +08:00
|
|
|
""" hook specifications for pytest plugins, invoked from main.py and builtin plugins. """
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2017-08-25 23:46:55 +08:00
|
|
|
from pluggy import HookspecMarker
|
2015-04-29 22:40:52 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
hookspec = HookspecMarker("pytest")
|
2015-04-25 17:29:11 +08:00
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
2015-04-25 17:29:11 +08:00
|
|
|
# Initialization hooks called for every plugin
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(historic=True)
|
2010-11-01 06:28:31 +08:00
|
|
|
def pytest_addhooks(pluginmanager):
|
2015-04-25 17:29:11 +08:00
|
|
|
"""called at plugin registration time to allow adding new hooks via a call to
|
2017-12-13 04:01:31 +08:00
|
|
|
``pluginmanager.add_hookspecs(module_or_class, prefix)``.
|
|
|
|
|
|
|
|
|
|
|
|
:param _pytest.config.PytestPluginManager pluginmanager: pytest plugin manager
|
2018-01-22 05:17:16 +08:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
This hook is incompatible with ``hookwrapper=True``.
|
2017-12-13 04:01:31 +08:00
|
|
|
"""
|
2010-11-01 06:28:31 +08:00
|
|
|
|
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(historic=True)
|
2010-05-02 22:36:53 +08:00
|
|
|
def pytest_namespace():
|
2017-03-01 00:12:16 +08:00
|
|
|
"""
|
2017-12-13 04:01:31 +08:00
|
|
|
(**Deprecated**) this hook causes direct monkeypatching on pytest, its use is strongly discouraged
|
2017-03-01 00:12:16 +08:00
|
|
|
return dict of name->object to be made globally available in
|
2017-12-13 04:01:31 +08:00
|
|
|
the pytest namespace.
|
|
|
|
|
|
|
|
This hook is called at plugin registration time.
|
2018-01-22 05:17:16 +08:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
This hook is incompatible with ``hookwrapper=True``.
|
2010-10-11 06:49:54 +08:00
|
|
|
"""
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(historic=True)
|
2015-04-25 19:38:30 +08:00
|
|
|
def pytest_plugin_registered(plugin, manager):
|
2017-12-13 04:01:31 +08:00
|
|
|
""" a new pytest plugin got registered.
|
|
|
|
|
|
|
|
:param plugin: the plugin module or instance
|
|
|
|
:param _pytest.config.PytestPluginManager manager: pytest plugin manager
|
2018-01-22 05:17:16 +08:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
This hook is incompatible with ``hookwrapper=True``.
|
2017-12-13 04:01:31 +08:00
|
|
|
"""
|
2015-04-25 19:38:30 +08:00
|
|
|
|
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(historic=True)
|
2010-05-02 22:36:53 +08:00
|
|
|
def pytest_addoption(parser):
|
2016-03-04 05:26:01 +08:00
|
|
|
"""register argparse-style options and ini-style config values,
|
|
|
|
called once at the beginning of a test run.
|
2012-11-06 21:09:12 +08:00
|
|
|
|
2016-03-04 05:26:01 +08:00
|
|
|
.. note::
|
2015-08-28 06:14:56 +08:00
|
|
|
|
2016-03-04 05:26:01 +08:00
|
|
|
This function should be implemented only in plugins or ``conftest.py``
|
2016-06-21 22:16:57 +08:00
|
|
|
files situated at the tests root directory due to how pytest
|
2016-03-04 05:26:01 +08:00
|
|
|
:ref:`discovers plugins during startup <pluginorder>`.
|
2012-11-06 21:09:12 +08:00
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
:arg _pytest.config.Parser parser: To add command line options, call
|
2012-11-06 21:09:12 +08:00
|
|
|
:py:func:`parser.addoption(...) <_pytest.config.Parser.addoption>`.
|
|
|
|
To add ini-file values call :py:func:`parser.addini(...)
|
|
|
|
<_pytest.config.Parser.addini>`.
|
|
|
|
|
|
|
|
Options can later be accessed through the
|
|
|
|
:py:class:`config <_pytest.config.Config>` object, respectively:
|
|
|
|
|
|
|
|
- :py:func:`config.getoption(name) <_pytest.config.Config.getoption>` to
|
|
|
|
retrieve the value of a command line option.
|
|
|
|
|
|
|
|
- :py:func:`config.getini(name) <_pytest.config.Config.getini>` to retrieve
|
|
|
|
a value read from an ini-style file.
|
|
|
|
|
|
|
|
The config object is passed around on many internal objects via the ``.config``
|
2017-12-13 04:01:31 +08:00
|
|
|
attribute or can be retrieved as the ``pytestconfig`` fixture.
|
2018-01-22 05:17:16 +08:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
This hook is incompatible with ``hookwrapper=True``.
|
2010-11-01 06:28:31 +08:00
|
|
|
"""
|
2010-10-11 06:49:54 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(historic=True)
|
2015-04-25 17:29:11 +08:00
|
|
|
def pytest_configure(config):
|
2017-07-05 07:47:15 +08:00
|
|
|
"""
|
|
|
|
Allows plugins and conftest files to perform initial configuration.
|
|
|
|
|
|
|
|
This hook is called for every plugin and initial conftest file
|
|
|
|
after command line options have been parsed.
|
|
|
|
|
|
|
|
After that, the hook is called for other conftest files as they are
|
|
|
|
imported.
|
|
|
|
|
2018-01-22 05:17:16 +08:00
|
|
|
.. note::
|
|
|
|
This hook is incompatible with ``hookwrapper=True``.
|
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
:arg _pytest.config.Config config: pytest config object
|
2015-04-25 17:29:11 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
# Bootstrapping hooks called for plugins registered early enough:
|
2018-01-06 23:31:38 +08:00
|
|
|
# internal and 3rd party plugins.
|
2015-04-25 17:29:11 +08:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2015-04-25 17:29:11 +08:00
|
|
|
def pytest_cmdline_parse(pluginmanager, args):
|
2017-06-13 10:45:35 +08:00
|
|
|
"""return initialized config object, parsing the specified args.
|
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
Stops at first non-None result, see :ref:`firstresult`
|
|
|
|
|
2018-01-06 23:31:38 +08:00
|
|
|
.. note::
|
|
|
|
This hook will not be called for ``conftest.py`` files, only for setuptools plugins.
|
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
:param _pytest.config.PytestPluginManager pluginmanager: pytest plugin manager
|
|
|
|
:param list[str] args: list of arguments passed on the command line
|
|
|
|
"""
|
2015-04-25 17:29:11 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-04-25 17:29:11 +08:00
|
|
|
def pytest_cmdline_preparse(config, args):
|
2017-12-13 04:01:31 +08:00
|
|
|
"""(**Deprecated**) modify command line arguments before option parsing.
|
|
|
|
|
|
|
|
This hook is considered deprecated and will be removed in a future pytest version. Consider
|
|
|
|
using :func:`pytest_load_initial_conftests` instead.
|
|
|
|
|
2018-01-06 23:31:38 +08:00
|
|
|
.. note::
|
|
|
|
This hook will not be called for ``conftest.py`` files, only for setuptools plugins.
|
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
:param _pytest.config.Config config: pytest config object
|
|
|
|
:param list[str] args: list of arguments passed on the command line
|
|
|
|
"""
|
2015-04-25 17:29:11 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2010-10-11 06:49:54 +08:00
|
|
|
def pytest_cmdline_main(config):
|
|
|
|
""" called for performing the main command line action. The default
|
2017-06-13 10:45:35 +08:00
|
|
|
implementation will invoke the configure hooks and runtest_mainloop.
|
|
|
|
|
2018-01-06 23:31:38 +08:00
|
|
|
.. note::
|
|
|
|
This hook will not be called for ``conftest.py`` files, only for setuptools plugins.
|
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
Stops at first non-None result, see :ref:`firstresult`
|
|
|
|
|
|
|
|
:param _pytest.config.Config config: pytest config object
|
|
|
|
"""
|
2009-07-18 00:07:37 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2016-03-13 00:31:32 +08:00
|
|
|
def pytest_load_initial_conftests(early_config, parser, args):
|
2014-03-25 21:43:58 +08:00
|
|
|
""" implements the loading of initial conftest files ahead
|
2017-12-13 04:01:31 +08:00
|
|
|
of command line option parsing.
|
|
|
|
|
2018-01-06 23:31:38 +08:00
|
|
|
.. note::
|
|
|
|
This hook will not be called for ``conftest.py`` files, only for setuptools plugins.
|
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
:param _pytest.config.Config early_config: pytest config object
|
|
|
|
:param list[str] args: list of arguments passed on the command line
|
|
|
|
:param _pytest.config.Parser parser: to add command line options
|
|
|
|
"""
|
2013-09-30 19:14:16 +08:00
|
|
|
|
2010-09-26 22:23:43 +08:00
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
2009-06-11 20:48:53 +08:00
|
|
|
# collection hooks
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
2009-06-15 21:15:40 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2010-11-01 07:27:12 +08:00
|
|
|
def pytest_collection(session):
|
2017-12-13 04:01:31 +08:00
|
|
|
"""Perform the collection protocol for the given session.
|
2017-06-13 10:45:35 +08:00
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
Stops at first non-None result, see :ref:`firstresult`.
|
|
|
|
|
|
|
|
:param _pytest.main.Session session: the pytest session object
|
|
|
|
"""
|
2010-09-15 16:30:50 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2010-11-07 17:19:58 +08:00
|
|
|
def pytest_collection_modifyitems(session, config, items):
|
2010-11-01 06:28:31 +08:00
|
|
|
""" called after collection has been performed, may filter or re-order
|
2017-12-13 04:01:31 +08:00
|
|
|
the items in-place.
|
|
|
|
|
|
|
|
:param _pytest.main.Session session: the pytest session object
|
|
|
|
:param _pytest.config.Config config: pytest config object
|
2017-12-17 22:19:01 +08:00
|
|
|
:param List[_pytest.nodes.Item] items: list of item objects
|
2017-12-13 04:01:31 +08:00
|
|
|
"""
|
2010-09-15 16:30:50 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2010-11-07 17:19:58 +08:00
|
|
|
def pytest_collection_finish(session):
|
2017-12-13 04:01:31 +08:00
|
|
|
""" called after collection has been performed and modified.
|
|
|
|
|
|
|
|
:param _pytest.main.Session session: the pytest session object
|
|
|
|
"""
|
2010-09-15 16:30:50 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2010-05-02 21:24:02 +08:00
|
|
|
def pytest_ignore_collect(path, config):
|
2010-10-11 18:54:28 +08:00
|
|
|
""" return True to prevent considering this path for collection.
|
|
|
|
This hook is consulted for all files and directories prior to calling
|
|
|
|
more specific hooks.
|
2017-06-13 10:45:35 +08:00
|
|
|
|
|
|
|
Stops at first non-None result, see :ref:`firstresult`
|
2017-12-13 04:01:31 +08:00
|
|
|
|
|
|
|
:param str path: the path to analyze
|
|
|
|
:param _pytest.config.Config config: pytest config object
|
2010-04-29 22:20:55 +08:00
|
|
|
"""
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2009-06-15 23:28:55 +08:00
|
|
|
def pytest_collect_directory(path, parent):
|
2017-06-13 10:45:35 +08:00
|
|
|
""" called before traversing a directory for collection files.
|
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
Stops at first non-None result, see :ref:`firstresult`
|
|
|
|
|
|
|
|
:param str path: the path to analyze
|
|
|
|
"""
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2009-06-11 20:48:53 +08:00
|
|
|
def pytest_collect_file(path, parent):
|
2010-10-11 18:54:28 +08:00
|
|
|
""" return collection Node or None for the given path. Any new node
|
2017-12-13 04:01:31 +08:00
|
|
|
needs to have the specified ``parent`` as a parent.
|
|
|
|
|
|
|
|
:param str path: the path to collect
|
|
|
|
"""
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2010-09-15 16:30:50 +08:00
|
|
|
# logging hooks for collection
|
2017-07-17 07:25:09 +08:00
|
|
|
|
|
|
|
|
2009-06-11 20:48:53 +08:00
|
|
|
def pytest_collectstart(collector):
|
|
|
|
""" collector starts collecting. """
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2010-11-01 06:28:31 +08:00
|
|
|
def pytest_itemcollected(item):
|
2010-09-15 16:30:50 +08:00
|
|
|
""" we just collected a test item. """
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2009-08-04 18:00:04 +08:00
|
|
|
def pytest_collectreport(report):
|
2009-06-11 20:48:53 +08:00
|
|
|
""" collector finished collecting. """
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
def pytest_deselected(items):
|
|
|
|
""" called for test items deselected by keyword. """
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2009-06-15 21:15:40 +08:00
|
|
|
def pytest_make_collect_report(collector):
|
2017-06-13 10:45:35 +08:00
|
|
|
""" perform ``collector.collect()`` and return a CollectReport.
|
|
|
|
|
|
|
|
Stops at first non-None result, see :ref:`firstresult` """
|
2009-06-15 21:15:40 +08:00
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
# Python test function related hooks
|
|
|
|
# -------------------------------------------------------------------------
|
2009-06-15 21:15:40 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2010-04-29 22:53:29 +08:00
|
|
|
def pytest_pycollect_makemodule(path, parent):
|
2010-07-27 03:15:15 +08:00
|
|
|
""" return a Module collector or None for the given path.
|
|
|
|
This hook will be called for each matching test module path.
|
|
|
|
The pytest_collect_file hook needs to be used if you want to
|
2010-04-29 22:53:29 +08:00
|
|
|
create test modules for files that do not match as a test module.
|
2017-06-13 10:45:35 +08:00
|
|
|
|
|
|
|
Stops at first non-None result, see :ref:`firstresult` """
|
2010-04-29 22:53:29 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2009-06-15 21:15:40 +08:00
|
|
|
def pytest_pycollect_makeitem(collector, name, obj):
|
2017-06-13 10:45:35 +08:00
|
|
|
""" return custom item/collector for a python object in a module, or None.
|
|
|
|
|
|
|
|
Stops at first non-None result, see :ref:`firstresult` """
|
2009-06-15 21:15:40 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2009-06-15 21:15:40 +08:00
|
|
|
def pytest_pyfunc_call(pyfuncitem):
|
2017-06-13 10:45:35 +08:00
|
|
|
""" call underlying test function.
|
|
|
|
|
|
|
|
Stops at first non-None result, see :ref:`firstresult` """
|
2009-06-15 21:15:40 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2009-06-15 21:15:40 +08:00
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
""" generate (multiple) parametrized calls to a test function."""
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2016-04-25 23:03:34 +08:00
|
|
|
@hookspec(firstresult=True)
|
2017-01-21 11:40:42 +08:00
|
|
|
def pytest_make_parametrize_id(config, val, argname):
|
2016-04-25 23:03:34 +08:00
|
|
|
"""Return a user-friendly string representation of the given ``val`` that will be used
|
|
|
|
by @pytest.mark.parametrize calls. Return None if the hook doesn't know about ``val``.
|
2017-01-16 11:09:46 +08:00
|
|
|
The parameter name is available as ``argname``, if required.
|
2017-06-13 10:45:35 +08:00
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
Stops at first non-None result, see :ref:`firstresult`
|
|
|
|
|
|
|
|
:param _pytest.config.Config config: pytest config object
|
|
|
|
:param val: the parametrized value
|
|
|
|
:param str argname: the automatic parameter name produced by pytest
|
|
|
|
"""
|
2016-04-25 23:03:34 +08:00
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
2010-07-27 03:15:15 +08:00
|
|
|
# generic runtest related hooks
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
2015-04-25 17:29:11 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2015-04-25 17:29:11 +08:00
|
|
|
def pytest_runtestloop(session):
|
|
|
|
""" called for performing the main runtest loop
|
2017-06-13 10:45:35 +08:00
|
|
|
(after collection finished).
|
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
Stops at first non-None result, see :ref:`firstresult`
|
|
|
|
|
|
|
|
:param _pytest.main.Session session: the pytest session object
|
|
|
|
"""
|
2015-04-25 17:29:11 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2014-10-01 20:55:54 +08:00
|
|
|
def pytest_itemstart(item, node):
|
2017-12-13 04:01:31 +08:00
|
|
|
"""(**Deprecated**) use pytest_runtest_logstart. """
|
2010-09-15 16:30:50 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2011-12-03 05:00:19 +08:00
|
|
|
def pytest_runtest_protocol(item, nextitem):
|
|
|
|
""" implements the runtest_setup/call/teardown protocol for
|
|
|
|
the given test item, including capturing exceptions and calling
|
|
|
|
reporting hooks.
|
|
|
|
|
|
|
|
:arg item: test item for which the runtest protocol is performed.
|
|
|
|
|
2014-06-03 13:21:02 +08:00
|
|
|
:arg nextitem: the scheduled-to-be-next test item (or None if this
|
2014-06-03 15:30:14 +08:00
|
|
|
is the end my friend). This argument is passed on to
|
|
|
|
:py:func:`pytest_runtest_teardown`.
|
2010-10-11 18:54:28 +08:00
|
|
|
|
|
|
|
:return boolean: True if no further hook implementations should be invoked.
|
2017-06-13 10:45:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
Stops at first non-None result, see :ref:`firstresult` """
|
2009-07-15 03:17:13 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2010-11-06 16:58:04 +08:00
|
|
|
def pytest_runtest_logstart(nodeid, location):
|
2018-01-10 08:17:39 +08:00
|
|
|
""" signal the start of running a single test item.
|
|
|
|
|
|
|
|
This hook will be called **before** :func:`pytest_runtest_setup`, :func:`pytest_runtest_call` and
|
|
|
|
:func:`pytest_runtest_teardown` hooks.
|
|
|
|
|
|
|
|
:param str nodeid: full id of the item
|
|
|
|
:param location: a triple of ``(filename, linenum, testname)``
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_runtest_logfinish(nodeid, location):
|
|
|
|
""" signal the complete finish of running a single test item.
|
|
|
|
|
|
|
|
This hook will be called **after** :func:`pytest_runtest_setup`, :func:`pytest_runtest_call` and
|
|
|
|
:func:`pytest_runtest_teardown` hooks.
|
|
|
|
|
|
|
|
:param str nodeid: full id of the item
|
|
|
|
:param location: a triple of ``(filename, linenum, testname)``
|
|
|
|
"""
|
2010-09-26 22:23:45 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2009-06-11 20:48:53 +08:00
|
|
|
def pytest_runtest_setup(item):
|
2010-10-11 18:54:28 +08:00
|
|
|
""" called before ``pytest_runtest_call(item)``. """
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2009-06-11 20:48:53 +08:00
|
|
|
def pytest_runtest_call(item):
|
2010-10-11 18:54:28 +08:00
|
|
|
""" called to execute the test ``item``. """
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2011-12-03 05:00:19 +08:00
|
|
|
def pytest_runtest_teardown(item, nextitem):
|
|
|
|
""" called after ``pytest_runtest_call``.
|
|
|
|
|
2014-06-03 15:30:14 +08:00
|
|
|
:arg nextitem: the scheduled-to-be-next test item (None if no further
|
|
|
|
test item is scheduled). This argument can be used to
|
|
|
|
perform exact teardowns, i.e. calling just enough finalizers
|
|
|
|
so that nextitem only needs to call setup-functions.
|
2011-12-03 05:00:19 +08:00
|
|
|
"""
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2009-06-11 20:48:53 +08:00
|
|
|
def pytest_runtest_makereport(item, call):
|
2010-11-13 18:10:45 +08:00
|
|
|
""" return a :py:class:`_pytest.runner.TestReport` object
|
2017-06-06 07:10:32 +08:00
|
|
|
for the given :py:class:`pytest.Item <_pytest.main.Item>` and
|
2010-11-13 18:10:45 +08:00
|
|
|
:py:class:`_pytest.runner.CallInfo`.
|
2017-06-13 10:45:35 +08:00
|
|
|
|
|
|
|
Stops at first non-None result, see :ref:`firstresult` """
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2009-08-04 18:00:04 +08:00
|
|
|
def pytest_runtest_logreport(report):
|
2011-11-09 01:53:46 +08:00
|
|
|
""" process a test setup/call/teardown report relating to
|
|
|
|
the respective phase of executing a test. """
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
2016-06-25 18:19:46 +08:00
|
|
|
# Fixture related hooks
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2016-06-25 18:19:46 +08:00
|
|
|
@hookspec(firstresult=True)
|
|
|
|
def pytest_fixture_setup(fixturedef, request):
|
2017-06-13 10:45:35 +08:00
|
|
|
""" performs fixture setup execution.
|
|
|
|
|
2018-01-22 03:50:26 +08:00
|
|
|
:return: The return value of the call to the fixture function
|
|
|
|
|
|
|
|
Stops at first non-None result, see :ref:`firstresult`
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
If the fixture function returns None, other implementations of
|
|
|
|
this hook function will continue to be called, according to the
|
|
|
|
behavior of the :ref:`firstresult` option.
|
|
|
|
"""
|
2016-06-25 18:19:46 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2017-11-12 21:14:55 +08:00
|
|
|
def pytest_fixture_post_finalizer(fixturedef, request):
|
2016-06-25 18:19:46 +08:00
|
|
|
""" called after fixture teardown, but before the cache is cleared so
|
|
|
|
the fixture result cache ``fixturedef.cached_result`` can
|
|
|
|
still be accessed."""
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
2010-07-27 03:15:15 +08:00
|
|
|
# test session related hooks
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
def pytest_sessionstart(session):
|
2017-12-13 04:01:31 +08:00
|
|
|
""" before session.main() is called.
|
|
|
|
|
|
|
|
:param _pytest.main.Session session: the pytest session object
|
|
|
|
"""
|
2009-07-15 03:17:13 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2009-07-20 20:01:40 +08:00
|
|
|
def pytest_sessionfinish(session, exitstatus):
|
2017-12-13 04:01:31 +08:00
|
|
|
""" whole test run finishes.
|
|
|
|
|
|
|
|
:param _pytest.main.Session session: the pytest session object
|
|
|
|
:param int exitstatus: the status which pytest will return to the system
|
|
|
|
"""
|
2009-07-15 03:17:13 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-04-25 17:29:11 +08:00
|
|
|
def pytest_unconfigure(config):
|
2017-12-13 04:01:31 +08:00
|
|
|
""" called before test process is exited.
|
|
|
|
|
|
|
|
:param _pytest.config.Config config: pytest config object
|
|
|
|
"""
|
2015-04-25 17:29:11 +08:00
|
|
|
|
2010-09-26 22:23:43 +08:00
|
|
|
|
2010-09-07 02:35:17 +08:00
|
|
|
# -------------------------------------------------------------------------
|
2017-02-17 13:52:06 +08:00
|
|
|
# hooks for customizing the assert methods
|
2010-09-07 02:35:17 +08:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
2010-10-03 01:00:47 +08:00
|
|
|
def pytest_assertrepr_compare(config, op, left, right):
|
|
|
|
"""return explanation for comparisons in failing assert expressions.
|
|
|
|
|
|
|
|
Return None for no custom explanation, otherwise return a list
|
|
|
|
of strings. The strings will be joined by newlines but any newlines
|
|
|
|
*in* a string will be escaped. Note that all but the first line will
|
2017-02-15 23:00:18 +08:00
|
|
|
be indented slightly, the intention is for the first line to be a summary.
|
2017-12-13 04:01:31 +08:00
|
|
|
|
|
|
|
:param _pytest.config.Config config: pytest config object
|
2010-09-07 02:35:17 +08:00
|
|
|
"""
|
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
2010-11-13 18:10:45 +08:00
|
|
|
# hooks for influencing reporting (invoked from _pytest_terminal)
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2012-06-21 17:07:22 +08:00
|
|
|
def pytest_report_header(config, startdir):
|
2017-07-27 21:34:49 +08:00
|
|
|
""" return a string or list of strings to be displayed as header info for terminal reporting.
|
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
:param _pytest.config.Config config: pytest config object
|
2017-07-27 21:34:49 +08:00
|
|
|
:param startdir: py.path object with the starting dir
|
2017-02-17 13:53:51 +08:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
This function should be implemented only in plugins or ``conftest.py``
|
|
|
|
files situated at the tests root directory due to how pytest
|
|
|
|
:ref:`discovers plugins during startup <pluginorder>`.
|
|
|
|
"""
|
2010-01-13 04:43:25 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2017-07-27 21:34:49 +08:00
|
|
|
def pytest_report_collectionfinish(config, startdir, items):
|
2017-07-28 02:33:22 +08:00
|
|
|
"""
|
|
|
|
.. versionadded:: 3.2
|
2017-07-28 03:24:58 +08:00
|
|
|
|
2017-07-28 02:33:22 +08:00
|
|
|
return a string or list of strings to be displayed after collection has finished successfully.
|
2017-07-27 21:34:49 +08:00
|
|
|
|
|
|
|
This strings will be displayed after the standard "collected X items" message.
|
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
:param _pytest.config.Config config: pytest config object
|
2017-07-27 21:34:49 +08:00
|
|
|
:param startdir: py.path object with the starting dir
|
|
|
|
:param items: list of pytest items that are going to be executed; this list should not be modified.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2009-08-06 21:02:38 +08:00
|
|
|
def pytest_report_teststatus(report):
|
2017-06-13 10:45:35 +08:00
|
|
|
""" return result-category, shortletter and verbose word for reporting.
|
|
|
|
|
|
|
|
Stops at first non-None result, see :ref:`firstresult` """
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2016-08-14 21:02:35 +08:00
|
|
|
def pytest_terminal_summary(terminalreporter, exitstatus):
|
2013-09-27 21:48:03 +08:00
|
|
|
""" add additional section in terminal summary reporting. """
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2015-09-03 00:49:49 +08:00
|
|
|
|
|
|
|
@hookspec(historic=True)
|
2014-03-12 05:10:17 +08:00
|
|
|
def pytest_logwarning(message, code, nodeid, fslocation):
|
|
|
|
""" process a warning specified by a message, a code string,
|
|
|
|
a nodeid and fslocation (both of which may be None
|
2018-01-27 22:28:43 +08:00
|
|
|
if the warning is not tied to a particular node/location).
|
2018-01-22 05:17:16 +08:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
This hook is incompatible with ``hookwrapper=True``.
|
|
|
|
"""
|
2014-03-12 05:10:17 +08:00
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
2010-07-27 03:15:15 +08:00
|
|
|
# doctest hooks
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-05-06 16:08:08 +08:00
|
|
|
@hookspec(firstresult=True)
|
2009-06-11 20:48:53 +08:00
|
|
|
def pytest_doctest_prepare_content(content):
|
2017-06-13 10:45:35 +08:00
|
|
|
""" return processed content for a given doctest
|
|
|
|
|
|
|
|
Stops at first non-None result, see :ref:`firstresult` """
|
2009-06-11 20:48:53 +08:00
|
|
|
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
2010-07-27 03:15:15 +08:00
|
|
|
# error handling and internal debugging hooks
|
2009-07-15 03:17:13 +08:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2013-09-06 17:56:04 +08:00
|
|
|
def pytest_internalerror(excrepr, excinfo):
|
2009-07-15 03:17:13 +08:00
|
|
|
""" called for internal errors. """
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2009-07-20 20:01:40 +08:00
|
|
|
def pytest_keyboard_interrupt(excinfo):
|
|
|
|
""" called for keyboard interrupt. """
|
2013-09-06 17:56:04 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2013-09-06 17:56:04 +08:00
|
|
|
def pytest_exception_interact(node, call, report):
|
2015-12-17 00:29:39 +08:00
|
|
|
"""called when an exception was raised which can potentially be
|
2013-09-06 17:56:04 +08:00
|
|
|
interactively handled.
|
|
|
|
|
|
|
|
This hook is only called if an exception was raised
|
2015-12-17 00:29:39 +08:00
|
|
|
that is not an internal exception like ``skip.Exception``.
|
2013-09-06 17:56:04 +08:00
|
|
|
"""
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-11-23 23:05:56 +08:00
|
|
|
def pytest_enter_pdb(config):
|
2015-11-23 22:59:56 +08:00
|
|
|
""" called upon pdb.set_trace(), can be used by plugins to take special
|
|
|
|
action just before the python debugger enters in interactive mode.
|
2015-11-23 23:05:56 +08:00
|
|
|
|
2017-12-13 04:01:31 +08:00
|
|
|
:param _pytest.config.Config config: pytest config object
|
2015-11-23 22:59:56 +08:00
|
|
|
"""
|