[svn r63822] simplifying and strictifying the internal calls to plugins using
the new "api" mechanism. --HG-- branch : trunk
This commit is contained in:
parent
d10eae0313
commit
0300b2109c
|
@ -438,8 +438,7 @@ class Directory(FSCollector):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def consider_file(self, path):
|
def consider_file(self, path):
|
||||||
return self.config.pytestplugins.call_each(
|
return self.config.api.pytest_collect_file(path=path, parent=self)
|
||||||
'pytest_collect_file', path=path, parent=self)
|
|
||||||
|
|
||||||
def consider_dir(self, path, usefilters=None):
|
def consider_dir(self, path, usefilters=None):
|
||||||
if usefilters is not None:
|
if usefilters is not None:
|
||||||
|
@ -447,8 +446,8 @@ class Directory(FSCollector):
|
||||||
res = self.config.pytestplugins.call_firstresult(
|
res = self.config.pytestplugins.call_firstresult(
|
||||||
'pytest_collect_recurse', path=path, parent=self)
|
'pytest_collect_recurse', path=path, parent=self)
|
||||||
if res is None or res:
|
if res is None or res:
|
||||||
return self.config.pytestplugins.call_each(
|
return self.config.api.pytest_collect_directory(
|
||||||
'pytest_collect_directory', path=path, parent=self)
|
path=path, parent=self)
|
||||||
|
|
||||||
class Item(Node):
|
class Item(Node):
|
||||||
""" a basic test item. """
|
""" a basic test item. """
|
||||||
|
|
|
@ -35,6 +35,7 @@ class PluginHooks:
|
||||||
|
|
||||||
def pytest_pymodule_makeitem(self, modcol, name, obj):
|
def pytest_pymodule_makeitem(self, modcol, 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. """
|
||||||
|
pytest_pymodule_makeitem.firstresult = True
|
||||||
|
|
||||||
def pytest_itemrun(self, item, pdb=None):
|
def pytest_itemrun(self, item, pdb=None):
|
||||||
""" run given test item and return test report. """
|
""" run given test item and return test report. """
|
||||||
|
@ -52,14 +53,22 @@ class PluginHooks:
|
||||||
|
|
||||||
def pytest_item_makereport(self, item, excinfo, when, outerr):
|
def pytest_item_makereport(self, item, excinfo, when, outerr):
|
||||||
""" return ItemTestReport event for the given test outcome. """
|
""" return ItemTestReport event for the given test outcome. """
|
||||||
|
pytest_item_makereport.firstresult = True
|
||||||
|
|
||||||
# reporting hooks (invoked from pytest_terminal.py)
|
# reporting hooks (invoked from pytest_terminal.py)
|
||||||
def pytest_report_teststatus(self, event):
|
def pytest_report_teststatus(self, rep):
|
||||||
""" return shortletter and verbose word. """
|
""" return shortletter and verbose word. """
|
||||||
|
pytest_report_teststatus.firstresult = True
|
||||||
|
|
||||||
def pytest_terminal_summary(self, terminalreporter):
|
def pytest_terminal_summary(self, terminalreporter):
|
||||||
""" add additional section in terminal summary reporting. """
|
""" 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:
|
class Events:
|
||||||
# Events
|
# Events
|
||||||
def pyevent(self, eventname, args, kwargs):
|
def pyevent(self, eventname, args, kwargs):
|
||||||
|
|
|
@ -154,8 +154,7 @@ class ReSTSyntaxTest(py.test.collect.Item):
|
||||||
class DoctestText(py.test.collect.Item):
|
class DoctestText(py.test.collect.Item):
|
||||||
def runtest(self):
|
def runtest(self):
|
||||||
content = self._normalize_linesep()
|
content = self._normalize_linesep()
|
||||||
newcontent = self.config.pytestplugins.call_firstresult(
|
newcontent = self.config.api.pytest_doctest_prepare_content(content=content)
|
||||||
'pytest_doctest_prepare_content', content=content)
|
|
||||||
if newcontent is not None:
|
if newcontent is not None:
|
||||||
content = newcontent
|
content = newcontent
|
||||||
s = content
|
s = content
|
||||||
|
|
|
@ -60,14 +60,14 @@ class TerminalReporter:
|
||||||
self.ensure_newline()
|
self.ensure_newline()
|
||||||
self._tw.sep(sep, title, **markup)
|
self._tw.sep(sep, title, **markup)
|
||||||
|
|
||||||
def getcategoryletterword(self, event):
|
def getcategoryletterword(self, rep):
|
||||||
res = self.config.pytestplugins.call_firstresult("pytest_report_teststatus", event=event)
|
res = self.config.api.pytest_report_teststatus(rep)
|
||||||
if res:
|
if res:
|
||||||
return res
|
return res
|
||||||
for cat in 'skipped failed passed ???'.split():
|
for cat in 'skipped failed passed ???'.split():
|
||||||
if getattr(event, cat, None):
|
if getattr(rep, cat, None):
|
||||||
break
|
break
|
||||||
return cat, self.getoutcomeletter(event), self.getoutcomeword(event)
|
return cat, self.getoutcomeletter(rep), self.getoutcomeword(rep)
|
||||||
|
|
||||||
def getoutcomeletter(self, rep):
|
def getoutcomeletter(self, rep):
|
||||||
return rep.shortrepr
|
return rep.shortrepr
|
||||||
|
@ -224,7 +224,7 @@ class TerminalReporter:
|
||||||
if exitstatus in (0, 1, 2):
|
if exitstatus in (0, 1, 2):
|
||||||
self.summary_failures()
|
self.summary_failures()
|
||||||
self.summary_skips()
|
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:
|
if excrepr is not None:
|
||||||
self.summary_final_exc(excrepr)
|
self.summary_final_exc(excrepr)
|
||||||
if exitstatus == 2:
|
if exitstatus == 2:
|
||||||
|
|
|
@ -22,12 +22,12 @@ class XfailPlugin(object):
|
||||||
res.failed = True
|
res.failed = True
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def pytest_report_teststatus(self, event):
|
def pytest_report_teststatus(self, rep):
|
||||||
""" return shortletter and verbose word. """
|
""" return shortletter and verbose word. """
|
||||||
if 'xfail' in event.keywords:
|
if 'xfail' in rep.keywords:
|
||||||
if event.skipped:
|
if rep.skipped:
|
||||||
return "xfailed", "x", "xfail"
|
return "xfailed", "x", "xfail"
|
||||||
elif event.failed:
|
elif rep.failed:
|
||||||
return "xpassed", "P", "xpass"
|
return "xpassed", "P", "xpass"
|
||||||
|
|
||||||
# a hook implemented called by the terminalreporter instance/plugin
|
# a hook implemented called by the terminalreporter instance/plugin
|
||||||
|
|
|
@ -140,8 +140,8 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
|
||||||
return self.join(name)
|
return self.join(name)
|
||||||
|
|
||||||
def makeitem(self, name, obj):
|
def makeitem(self, name, obj):
|
||||||
res = self.config.pytestplugins.call_firstresult(
|
res = self.config.api.pytest_pymodule_makeitem(
|
||||||
"pytest_pymodule_makeitem", modcol=self, name=name, obj=obj)
|
modcol=self, name=name, obj=obj)
|
||||||
if res:
|
if res:
|
||||||
return res
|
return res
|
||||||
if (self.classnamefilter(name)) and \
|
if (self.classnamefilter(name)) and \
|
||||||
|
@ -349,8 +349,8 @@ class Function(FunctionMixin, py.test.collect.Item):
|
||||||
""" execute the given test function. """
|
""" execute the given test function. """
|
||||||
if not self._deprecated_testexecution():
|
if not self._deprecated_testexecution():
|
||||||
kw = self.lookup_allargs()
|
kw = self.lookup_allargs()
|
||||||
ret = self.config.pytestplugins.call_firstresult(
|
ret = self.config.api.pytest_pyfunc_call(
|
||||||
"pytest_pyfunc_call", pyfuncitem=self, args=self._args, kwargs=kw)
|
pyfuncitem=self, args=self._args, kwargs=kw)
|
||||||
|
|
||||||
def lookup_allargs(self):
|
def lookup_allargs(self):
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
|
|
@ -102,12 +102,12 @@ class PytestPlugins(object):
|
||||||
assert not hasattr(self, '_config')
|
assert not hasattr(self, '_config')
|
||||||
config.bus.register(self)
|
config.bus.register(self)
|
||||||
self._config = config
|
self._config = config
|
||||||
self.pyplugins.call_each("pytest_configure", config=self._config)
|
config.api.pytest_configure(config=self._config)
|
||||||
|
|
||||||
def do_unconfigure(self, config):
|
def do_unconfigure(self, config):
|
||||||
config = self._config
|
config = self._config
|
||||||
del self._config
|
del self._config
|
||||||
self.pyplugins.call_each("pytest_unconfigure", config=config)
|
config.api.pytest_unconfigure(config=config)
|
||||||
config.bus.unregister(self)
|
config.bus.unregister(self)
|
||||||
|
|
||||||
def do_itemrun(self, item, pdb=None):
|
def do_itemrun(self, item, pdb=None):
|
||||||
|
|
|
@ -31,9 +31,8 @@ def basic_run_report(item, pdb=None):
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
testrep = item.config.pytestplugins.call_firstresult(
|
testrep = item.config.api.pytest_item_makereport(
|
||||||
"pytest_item_makereport", item=item,
|
item=item, excinfo=excinfo, when=when, outerr=outerr)
|
||||||
excinfo=excinfo, when=when, outerr=outerr)
|
|
||||||
if pdb and testrep.failed:
|
if pdb and testrep.failed:
|
||||||
tw = py.io.TerminalWriter()
|
tw = py.io.TerminalWriter()
|
||||||
testrep.toterminal(tw)
|
testrep.toterminal(tw)
|
||||||
|
|
Loading…
Reference in New Issue