backout, the _memoizedcall change worked only due to a local effect

This commit is contained in:
Ronny Pfannschmidt 2012-09-24 11:36:24 +02:00
parent 6e5f491a42
commit 9568ff3b23
3 changed files with 24 additions and 6 deletions

View File

@ -251,6 +251,24 @@ class Node(object):
def teardown(self): def teardown(self):
pass pass
def _memoizedcall(self, attrname, function):
exattrname = "_ex_" + attrname
failure = getattr(self, exattrname, None)
if failure is not None:
py.builtin._reraise(failure[0], failure[1], failure[2])
if hasattr(self, attrname):
return getattr(self, attrname)
try:
res = function()
except py.builtin._sysex:
raise
except:
failure = py.std.sys.exc_info()
setattr(self, exattrname, failure)
raise
setattr(self, attrname, res)
return res
def listchain(self): def listchain(self):
""" return list of all parent collectors up to self, """ return list of all parent collectors up to self,
starting from root of collection tree. """ starting from root of collection tree. """
@ -327,6 +345,10 @@ class Collector(Node):
return str(exc.args[0]) return str(exc.args[0])
return self._repr_failure_py(excinfo, style="short") return self._repr_failure_py(excinfo, style="short")
def _memocollect(self):
""" internal helper method to cache results of calling collect(). """
return self._memoizedcall('_collected', lambda: list(self.collect()))
def _prunetraceback(self, excinfo): def _prunetraceback(self, excinfo):
if hasattr(self, 'fspath'): if hasattr(self, 'fspath'):
path = self.fspath path = self.fspath

View File

@ -332,12 +332,8 @@ def transfer_markers(funcobj, cls, mod):
class Module(pytest.File, PyCollector): class Module(pytest.File, PyCollector):
""" Collector for test classes and functions. """ """ Collector for test classes and functions. """
_obj = None
def _getobj(self): def _getobj(self):
if self._obj is None: return self._memoizedcall('_obj', self._importtestmodule)
self._obj = self._importtestmodule()
return _obj
def collect(self): def collect(self):
self.session.funcargmanager._parsefactories(self.obj, self.nodeid) self.session.funcargmanager._parsefactories(self.obj, self.nodeid)

View File

@ -244,7 +244,7 @@ class TeardownErrorReport(BaseReport):
self.__dict__.update(extra) self.__dict__.update(extra)
def pytest_make_collect_report(collector): def pytest_make_collect_report(collector):
call = CallInfo(lambda: list(collector.collect()), "collect") call = CallInfo(collector._memocollect, "memocollect")
longrepr = None longrepr = None
if not call.excinfo: if not call.excinfo:
outcome = "passed" outcome = "passed"