2009-04-03 03:16:57 +08:00
|
|
|
"""
|
2009-04-09 08:45:46 +08:00
|
|
|
API definitions for pytest plugin hooks
|
2009-04-03 03:16:57 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
class PluginHooks:
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Command line and configuration hooks
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
def pytest_addoption(self, parser):
|
|
|
|
""" called before commandline parsing. """
|
|
|
|
|
|
|
|
def pytest_configure(self, config):
|
|
|
|
""" called after command line options have been parsed.
|
|
|
|
and all plugins and initial conftest files been loaded.
|
|
|
|
``config`` provides access to all such configuration values.
|
|
|
|
"""
|
2009-04-09 23:03:58 +08:00
|
|
|
|
2009-04-03 03:16:57 +08:00
|
|
|
def pytest_unconfigure(self, config):
|
|
|
|
""" called before test process is exited.
|
|
|
|
"""
|
|
|
|
|
2009-04-09 23:03:58 +08:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# test Session related hooks
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2009-05-23 03:53:26 +08:00
|
|
|
def pytest_sessionstart(self, session):
|
|
|
|
""" before session.main() is called. """
|
2009-04-09 23:03:58 +08:00
|
|
|
|
2009-05-23 03:53:26 +08:00
|
|
|
def pytest_sessionfinish(self, session, exitstatus, excrepr=None):
|
2009-04-09 23:03:58 +08:00
|
|
|
""" whole test run finishes. """
|
|
|
|
|
|
|
|
def pytest_deselected(self, items):
|
|
|
|
""" collected items that were deselected (by keyword). """
|
|
|
|
|
2009-04-03 03:16:57 +08:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# collection hooks
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
def pytest_collect_file(self, path, parent):
|
|
|
|
""" return Collection node or None. """
|
|
|
|
|
|
|
|
def pytest_collect_recurse(self, path, parent):
|
|
|
|
""" return True/False to cause/prevent recursion into given directory.
|
|
|
|
return None if you do not want to make the decision.
|
|
|
|
"""
|
2009-04-10 02:39:59 +08:00
|
|
|
pytest_collect_recurse.firstresult = True
|
2009-04-03 03:16:57 +08:00
|
|
|
|
|
|
|
def pytest_collect_directory(self, path, parent):
|
|
|
|
""" return Collection node or None. """
|
|
|
|
|
2009-05-08 05:12:17 +08:00
|
|
|
def pytest_pycollect_obj(self, collector, name, obj):
|
2009-04-03 03:16:57 +08:00
|
|
|
""" return custom item/collector for a python object in a module, or None. """
|
2009-05-08 05:12:17 +08:00
|
|
|
pytest_pycollect_obj.firstresult = True
|
2009-04-03 03:16:57 +08:00
|
|
|
|
2009-05-13 05:32:19 +08:00
|
|
|
def pytest_generate_tests(self, metafunc):
|
2009-05-12 01:23:57 +08:00
|
|
|
""" generate (multiple) parametrized calls to a test function."""
|
|
|
|
|
2009-04-09 08:53:45 +08:00
|
|
|
def pytest_collectstart(self, collector):
|
|
|
|
""" collector starts collecting. """
|
|
|
|
|
|
|
|
def pytest_collectreport(self, rep):
|
|
|
|
""" collector finished collecting. """
|
2009-04-04 05:18:41 +08:00
|
|
|
|
2009-05-23 01:57:21 +08:00
|
|
|
# XXX rename to item_collected()? meaning in distribution context?
|
|
|
|
def pytest_itemstart(self, item, node=None):
|
|
|
|
""" test item gets collected. """
|
|
|
|
|
2009-04-03 03:16:57 +08:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# runtest related hooks
|
|
|
|
# ------------------------------------------------------------------------------
|
2009-05-23 01:57:21 +08:00
|
|
|
|
2009-04-09 08:53:45 +08:00
|
|
|
def pytest_itemrun(self, item, pdb=None):
|
|
|
|
""" run given test item and return test report. """
|
2009-05-21 04:02:08 +08:00
|
|
|
pytest_itemrun.firstresult = True
|
2009-04-03 03:16:57 +08:00
|
|
|
|
2009-04-08 23:19:46 +08:00
|
|
|
def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
|
2009-04-03 03:16:57 +08:00
|
|
|
""" return True if we consumed/did the call to the python function item. """
|
2009-04-18 01:25:15 +08:00
|
|
|
pytest_pyfunc_call.firstresult = True
|
2009-04-03 03:16:57 +08:00
|
|
|
|
|
|
|
def pytest_item_makereport(self, item, excinfo, when, outerr):
|
2009-05-23 01:57:21 +08:00
|
|
|
""" make ItemTestReport for the specified test outcome. """
|
2009-04-08 18:06:21 +08:00
|
|
|
pytest_item_makereport.firstresult = True
|
2009-04-03 03:16:57 +08:00
|
|
|
|
2009-04-09 07:33:48 +08:00
|
|
|
def pytest_itemtestreport(self, rep):
|
2009-05-23 01:57:21 +08:00
|
|
|
""" process item test report. """
|
2009-04-09 07:33:48 +08:00
|
|
|
|
2009-04-09 08:53:45 +08:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# reporting hooks (invoked from pytest_terminal.py)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
def pytest_report_teststatus(self, rep):
|
|
|
|
""" return shortletter and verbose word. """
|
|
|
|
pytest_report_teststatus.firstresult = True
|
2009-04-09 07:33:48 +08:00
|
|
|
|
2009-04-09 08:53:45 +08:00
|
|
|
def pytest_terminal_summary(self, terminalreporter):
|
|
|
|
""" add additional section in terminal summary reporting. """
|
|
|
|
|
2009-05-12 23:02:22 +08:00
|
|
|
def pytest_report_iteminfo(self, item):
|
|
|
|
""" return (fspath, lineno, name) for the item.
|
|
|
|
the information is used for result display and to sort tests
|
|
|
|
"""
|
|
|
|
pytest_report_iteminfo.firstresult = True
|
|
|
|
|
2009-04-09 08:53:45 +08:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# doctest hooks
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
def pytest_doctest_prepare_content(self, content):
|
|
|
|
""" return processed content for a given doctest"""
|
|
|
|
pytest_doctest_prepare_content.firstresult = True
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# misc hooks
|
|
|
|
# ------------------------------------------------------------------------------
|
2009-04-09 07:33:48 +08:00
|
|
|
|
|
|
|
def pytest_plugin_registered(self, plugin):
|
|
|
|
""" a new py lib plugin got registered. """
|
|
|
|
|
|
|
|
def pytest_plugin_unregistered(self, plugin):
|
|
|
|
""" a py lib plugin got unregistered. """
|
|
|
|
|
2009-04-09 23:03:58 +08:00
|
|
|
def pytest_internalerror(self, excrepr):
|
|
|
|
""" called for internal errors. """
|
|
|
|
|
|
|
|
def pytest_trace(self, category, msg):
|
|
|
|
""" called for debug info. """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# distributed testing
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2009-04-09 07:33:48 +08:00
|
|
|
def pytest_testnodeready(self, node):
|
|
|
|
""" Test Node is ready to operate. """
|
|
|
|
|
|
|
|
def pytest_testnodedown(self, node, error):
|
|
|
|
""" Test Node is down. """
|
|
|
|
|
2009-04-09 07:50:02 +08:00
|
|
|
def pytest_rescheduleitems(self, items):
|
|
|
|
""" reschedule Items from a node that went down. """
|
|
|
|
|
|
|
|
def pytest_looponfailinfo(self, failreports, rootdirs):
|
|
|
|
""" info for repeating failing tests. """
|
2009-04-09 07:41:35 +08:00
|
|
|
|