summaryrefslogtreecommitdiff
path: root/lib/spack/external/_pytest/hookspec.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spack/external/_pytest/hookspec.py')
-rw-r--r--lib/spack/external/_pytest/hookspec.py157
1 files changed, 133 insertions, 24 deletions
diff --git a/lib/spack/external/_pytest/hookspec.py b/lib/spack/external/_pytest/hookspec.py
index b5f51eccf5..e5c966e58b 100644
--- a/lib/spack/external/_pytest/hookspec.py
+++ b/lib/spack/external/_pytest/hookspec.py
@@ -8,6 +8,7 @@ hookspec = HookspecMarker("pytest")
# Initialization hooks called for every plugin
# -------------------------------------------------------------------------
+
@hookspec(historic=True)
def pytest_addhooks(pluginmanager):
"""called at plugin registration time to allow adding new hooks via a call to
@@ -16,11 +17,14 @@ def pytest_addhooks(pluginmanager):
@hookspec(historic=True)
def pytest_namespace():
- """return dict of name->object to be made globally available in
+ """
+ DEPRECATED: this hook causes direct monkeypatching on pytest, its use is strongly discouraged
+ return dict of name->object to be made globally available in
the pytest namespace. This hook is called at plugin registration
time.
"""
+
@hookspec(historic=True)
def pytest_plugin_registered(plugin, manager):
""" a new pytest plugin got registered. """
@@ -56,11 +60,20 @@ def pytest_addoption(parser):
via (deprecated) ``pytest.config``.
"""
+
@hookspec(historic=True)
def pytest_configure(config):
- """ called after command line options have been parsed
- and all plugins and initial conftest files been loaded.
- This hook is called for every plugin.
+ """
+ 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.
+
+ :arg config: pytest config object
+ :type config: _pytest.config.Config
"""
# -------------------------------------------------------------------------
@@ -69,17 +82,25 @@ def pytest_configure(config):
# discoverable conftest.py local plugins.
# -------------------------------------------------------------------------
+
@hookspec(firstresult=True)
def pytest_cmdline_parse(pluginmanager, args):
- """return initialized config object, parsing the specified args. """
+ """return initialized config object, parsing the specified args.
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
def pytest_cmdline_preparse(config, args):
"""(deprecated) modify command line arguments before option parsing. """
+
@hookspec(firstresult=True)
def pytest_cmdline_main(config):
""" called for performing the main command line action. The default
- implementation will invoke the configure hooks and runtest_mainloop. """
+ implementation will invoke the configure hooks and runtest_mainloop.
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
def pytest_load_initial_conftests(early_config, parser, args):
""" implements the loading of initial conftest files ahead
@@ -92,88 +113,124 @@ def pytest_load_initial_conftests(early_config, parser, args):
@hookspec(firstresult=True)
def pytest_collection(session):
- """ perform the collection protocol for the given session. """
+ """ perform the collection protocol for the given session.
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
def pytest_collection_modifyitems(session, config, items):
""" called after collection has been performed, may filter or re-order
the items in-place."""
+
def pytest_collection_finish(session):
""" called after collection has been performed and modified. """
+
@hookspec(firstresult=True)
def pytest_ignore_collect(path, config):
""" return True to prevent considering this path for collection.
This hook is consulted for all files and directories prior to calling
more specific hooks.
+
+ Stops at first non-None result, see :ref:`firstresult`
"""
+
@hookspec(firstresult=True)
def pytest_collect_directory(path, parent):
- """ called before traversing a directory for collection files. """
+ """ called before traversing a directory for collection files.
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
def pytest_collect_file(path, parent):
""" return collection Node or None for the given path. Any new node
needs to have the specified ``parent`` as a parent."""
# logging hooks for collection
+
+
def pytest_collectstart(collector):
""" collector starts collecting. """
+
def pytest_itemcollected(item):
""" we just collected a test item. """
+
def pytest_collectreport(report):
""" collector finished collecting. """
+
def pytest_deselected(items):
""" called for test items deselected by keyword. """
+
@hookspec(firstresult=True)
def pytest_make_collect_report(collector):
- """ perform ``collector.collect()`` and return a CollectReport. """
+ """ perform ``collector.collect()`` and return a CollectReport.
+
+ Stops at first non-None result, see :ref:`firstresult` """
# -------------------------------------------------------------------------
# Python test function related hooks
# -------------------------------------------------------------------------
+
@hookspec(firstresult=True)
def pytest_pycollect_makemodule(path, parent):
""" 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
create test modules for files that do not match as a test module.
- """
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
@hookspec(firstresult=True)
def pytest_pycollect_makeitem(collector, name, obj):
- """ return custom item/collector for a python object in a module, or None. """
+ """ return custom item/collector for a python object in a module, or None.
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
@hookspec(firstresult=True)
def pytest_pyfunc_call(pyfuncitem):
- """ call underlying test function. """
+ """ call underlying test function.
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
def pytest_generate_tests(metafunc):
""" generate (multiple) parametrized calls to a test function."""
+
@hookspec(firstresult=True)
-def pytest_make_parametrize_id(config, val):
+def pytest_make_parametrize_id(config, val, argname):
"""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``.
- """
+ The parameter name is available as ``argname``, if required.
+
+ Stops at first non-None result, see :ref:`firstresult` """
# -------------------------------------------------------------------------
# generic runtest related hooks
# -------------------------------------------------------------------------
+
@hookspec(firstresult=True)
def pytest_runtestloop(session):
""" called for performing the main runtest loop
- (after collection finished). """
+ (after collection finished).
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
def pytest_itemstart(item, node):
""" (deprecated, use pytest_runtest_logstart). """
+
@hookspec(firstresult=True)
def pytest_runtest_protocol(item, nextitem):
""" implements the runtest_setup/call/teardown protocol for
@@ -187,17 +244,23 @@ def pytest_runtest_protocol(item, nextitem):
:py:func:`pytest_runtest_teardown`.
:return boolean: True if no further hook implementations should be invoked.
- """
+
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
def pytest_runtest_logstart(nodeid, location):
""" signal the start of running a single test item. """
+
def pytest_runtest_setup(item):
""" called before ``pytest_runtest_call(item)``. """
+
def pytest_runtest_call(item):
""" called to execute the test ``item``. """
+
def pytest_runtest_teardown(item, nextitem):
""" called after ``pytest_runtest_call``.
@@ -207,12 +270,15 @@ def pytest_runtest_teardown(item, nextitem):
so that nextitem only needs to call setup-functions.
"""
+
@hookspec(firstresult=True)
def pytest_runtest_makereport(item, call):
""" return a :py:class:`_pytest.runner.TestReport` object
- for the given :py:class:`pytest.Item` and
+ for the given :py:class:`pytest.Item <_pytest.main.Item>` and
:py:class:`_pytest.runner.CallInfo`.
- """
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
def pytest_runtest_logreport(report):
""" process a test setup/call/teardown report relating to
@@ -222,9 +288,13 @@ def pytest_runtest_logreport(report):
# Fixture related hooks
# -------------------------------------------------------------------------
+
@hookspec(firstresult=True)
def pytest_fixture_setup(fixturedef, request):
- """ performs fixture setup execution. """
+ """ performs fixture setup execution.
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
def pytest_fixture_post_finalizer(fixturedef):
""" called after fixture teardown, but before the cache is cleared so
@@ -235,18 +305,21 @@ def pytest_fixture_post_finalizer(fixturedef):
# test session related hooks
# -------------------------------------------------------------------------
+
def pytest_sessionstart(session):
""" before session.main() is called. """
+
def pytest_sessionfinish(session, exitstatus):
""" whole test run finishes. """
+
def pytest_unconfigure(config):
""" called before test process is exited. """
# -------------------------------------------------------------------------
-# hooks for customising the assert methods
+# hooks for customizing the assert methods
# -------------------------------------------------------------------------
def pytest_assertrepr_compare(config, op, left, right):
@@ -255,19 +328,48 @@ def pytest_assertrepr_compare(config, op, left, right):
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
- be indented sligthly, the intention is for the first line to be a summary.
+ be indented slightly, the intention is for the first line to be a summary.
"""
# -------------------------------------------------------------------------
# hooks for influencing reporting (invoked from _pytest_terminal)
# -------------------------------------------------------------------------
+
def pytest_report_header(config, startdir):
- """ return a string to be displayed as header info for terminal reporting."""
+ """ return a string or list of strings to be displayed as header info for terminal reporting.
+
+ :param config: the pytest config object.
+ :param startdir: py.path object with the starting dir
+
+ .. 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>`.
+ """
+
+
+def pytest_report_collectionfinish(config, startdir, items):
+ """
+ .. versionadded:: 3.2
+
+ return a string or list of strings to be displayed after collection has finished successfully.
+
+ This strings will be displayed after the standard "collected X items" message.
+
+ :param config: the pytest config object.
+ :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.
+ """
+
@hookspec(firstresult=True)
def pytest_report_teststatus(report):
- """ return result-category, shortletter and verbose word for reporting."""
+ """ return result-category, shortletter and verbose word for reporting.
+
+ Stops at first non-None result, see :ref:`firstresult` """
+
def pytest_terminal_summary(terminalreporter, exitstatus):
""" add additional section in terminal summary reporting. """
@@ -283,20 +385,26 @@ def pytest_logwarning(message, code, nodeid, fslocation):
# doctest hooks
# -------------------------------------------------------------------------
+
@hookspec(firstresult=True)
def pytest_doctest_prepare_content(content):
- """ return processed content for a given doctest"""
+ """ return processed content for a given doctest
+
+ Stops at first non-None result, see :ref:`firstresult` """
# -------------------------------------------------------------------------
# error handling and internal debugging hooks
# -------------------------------------------------------------------------
+
def pytest_internalerror(excrepr, excinfo):
""" called for internal errors. """
+
def pytest_keyboard_interrupt(excinfo):
""" called for keyboard interrupt. """
+
def pytest_exception_interact(node, call, report):
"""called when an exception was raised which can potentially be
interactively handled.
@@ -305,6 +413,7 @@ def pytest_exception_interact(node, call, report):
that is not an internal exception like ``skip.Exception``.
"""
+
def pytest_enter_pdb(config):
""" called upon pdb.set_trace(), can be used by plugins to take special
action just before the python debugger enters in interactive mode.