diff --git a/py/test/collect.py b/py/test/collect.py index b8b066cae..d980cabda 100644 --- a/py/test/collect.py +++ b/py/test/collect.py @@ -438,8 +438,7 @@ class Directory(FSCollector): return res def consider_file(self, path): - return self.config.pytestplugins.call_each( - 'pytest_collect_file', path=path, parent=self) + return self.config.api.pytest_collect_file(path=path, parent=self) def consider_dir(self, path, usefilters=None): if usefilters is not None: @@ -447,8 +446,8 @@ class Directory(FSCollector): res = self.config.pytestplugins.call_firstresult( 'pytest_collect_recurse', path=path, parent=self) if res is None or res: - return self.config.pytestplugins.call_each( - 'pytest_collect_directory', path=path, parent=self) + return self.config.api.pytest_collect_directory( + path=path, parent=self) class Item(Node): """ a basic test item. """ diff --git a/py/test/plugin/api.py b/py/test/plugin/api.py index cb657c3e9..a8d51a857 100644 --- a/py/test/plugin/api.py +++ b/py/test/plugin/api.py @@ -35,6 +35,7 @@ class PluginHooks: def pytest_pymodule_makeitem(self, modcol, name, obj): """ return custom item/collector for a python object in a module, or None. """ + pytest_pymodule_makeitem.firstresult = True def pytest_itemrun(self, item, pdb=None): """ run given test item and return test report. """ @@ -52,14 +53,22 @@ class PluginHooks: def pytest_item_makereport(self, item, excinfo, when, outerr): """ return ItemTestReport event for the given test outcome. """ + pytest_item_makereport.firstresult = True # reporting hooks (invoked from pytest_terminal.py) - def pytest_report_teststatus(self, event): + def pytest_report_teststatus(self, rep): """ return shortletter and verbose word. """ + pytest_report_teststatus.firstresult = True def pytest_terminal_summary(self, terminalreporter): """ add additional section in terminal summary reporting. """ + # doctest hooks (invoked from pytest_terminal.py) + def pytest_doctest_prepare_content(self, content): + """ return processed content for a given doctest""" + pytest_doctest_prepare_content.firstresult = True + + class Events: # Events def pyevent(self, eventname, args, kwargs): diff --git a/py/test/plugin/pytest_restdoc.py b/py/test/plugin/pytest_restdoc.py index 211b0a5b5..458292a2c 100644 --- a/py/test/plugin/pytest_restdoc.py +++ b/py/test/plugin/pytest_restdoc.py @@ -154,8 +154,7 @@ class ReSTSyntaxTest(py.test.collect.Item): class DoctestText(py.test.collect.Item): def runtest(self): content = self._normalize_linesep() - newcontent = self.config.pytestplugins.call_firstresult( - 'pytest_doctest_prepare_content', content=content) + newcontent = self.config.api.pytest_doctest_prepare_content(content=content) if newcontent is not None: content = newcontent s = content diff --git a/py/test/plugin/pytest_terminal.py b/py/test/plugin/pytest_terminal.py index a476eb803..9867c0767 100644 --- a/py/test/plugin/pytest_terminal.py +++ b/py/test/plugin/pytest_terminal.py @@ -60,14 +60,14 @@ class TerminalReporter: self.ensure_newline() self._tw.sep(sep, title, **markup) - def getcategoryletterword(self, event): - res = self.config.pytestplugins.call_firstresult("pytest_report_teststatus", event=event) + def getcategoryletterword(self, rep): + res = self.config.api.pytest_report_teststatus(rep) if res: return res for cat in 'skipped failed passed ???'.split(): - if getattr(event, cat, None): + if getattr(rep, cat, None): break - return cat, self.getoutcomeletter(event), self.getoutcomeword(event) + return cat, self.getoutcomeletter(rep), self.getoutcomeword(rep) def getoutcomeletter(self, rep): return rep.shortrepr @@ -224,7 +224,7 @@ class TerminalReporter: if exitstatus in (0, 1, 2): self.summary_failures() self.summary_skips() - self.config.pytestplugins.call_each("pytest_terminal_summary", terminalreporter=self) + self.config.api.pytest_terminal_summary(terminalreporter=self) if excrepr is not None: self.summary_final_exc(excrepr) if exitstatus == 2: diff --git a/py/test/plugin/pytest_xfail.py b/py/test/plugin/pytest_xfail.py index 413eb7aaa..8e7a73ef3 100644 --- a/py/test/plugin/pytest_xfail.py +++ b/py/test/plugin/pytest_xfail.py @@ -22,12 +22,12 @@ class XfailPlugin(object): res.failed = True return res - def pytest_report_teststatus(self, event): + def pytest_report_teststatus(self, rep): """ return shortletter and verbose word. """ - if 'xfail' in event.keywords: - if event.skipped: + if 'xfail' in rep.keywords: + if rep.skipped: return "xfailed", "x", "xfail" - elif event.failed: + elif rep.failed: return "xpassed", "P", "xpass" # a hook implemented called by the terminalreporter instance/plugin diff --git a/py/test/pycollect.py b/py/test/pycollect.py index 41fe92fc2..e879a6a00 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -140,8 +140,8 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector): return self.join(name) def makeitem(self, name, obj): - res = self.config.pytestplugins.call_firstresult( - "pytest_pymodule_makeitem", modcol=self, name=name, obj=obj) + res = self.config.api.pytest_pymodule_makeitem( + modcol=self, name=name, obj=obj) if res: return res if (self.classnamefilter(name)) and \ @@ -349,8 +349,8 @@ class Function(FunctionMixin, py.test.collect.Item): """ execute the given test function. """ if not self._deprecated_testexecution(): kw = self.lookup_allargs() - ret = self.config.pytestplugins.call_firstresult( - "pytest_pyfunc_call", pyfuncitem=self, args=self._args, kwargs=kw) + ret = self.config.api.pytest_pyfunc_call( + pyfuncitem=self, args=self._args, kwargs=kw) def lookup_allargs(self): kwargs = {} diff --git a/py/test/pytestplugin.py b/py/test/pytestplugin.py index acf14c06f..fb8a9eb7e 100644 --- a/py/test/pytestplugin.py +++ b/py/test/pytestplugin.py @@ -102,12 +102,12 @@ class PytestPlugins(object): assert not hasattr(self, '_config') config.bus.register(self) self._config = config - self.pyplugins.call_each("pytest_configure", config=self._config) + config.api.pytest_configure(config=self._config) def do_unconfigure(self, config): config = self._config del self._config - self.pyplugins.call_each("pytest_unconfigure", config=config) + config.api.pytest_unconfigure(config=config) config.bus.unregister(self) def do_itemrun(self, item, pdb=None): diff --git a/py/test/runner.py b/py/test/runner.py index 0b4d50bde..25a02cd80 100644 --- a/py/test/runner.py +++ b/py/test/runner.py @@ -31,9 +31,8 @@ def basic_run_report(item, pdb=None): raise except: excinfo = py.code.ExceptionInfo() - testrep = item.config.pytestplugins.call_firstresult( - "pytest_item_makereport", item=item, - excinfo=excinfo, when=when, outerr=outerr) + testrep = item.config.api.pytest_item_makereport( + item=item, excinfo=excinfo, when=when, outerr=outerr) if pdb and testrep.failed: tw = py.io.TerminalWriter() testrep.toterminal(tw)