Commits

holger krekel committed 8698616

copy latest pytest release candidate

Comments (0)

Files changed (4)

 class PluginManager(object):
     def __init__(self, load=False):
         self._name2plugin = {}
+        self._listattrcache = {}
         self._plugins = []
         self._hints = []
         self.trace = TagTracer().get("pluginmanage")
     def listattr(self, attrname, plugins=None):
         if plugins is None:
             plugins = self._plugins
+        key = (attrname,) + tuple(plugins)
+        try:
+            return list(self._listattrcache[key])
+        except KeyError:
+            pass
         l = []
         last = []
         for plugin in plugins:
             except AttributeError:
                 continue
         l.extend(last)
+        self._listattrcache[key] = list(l)
         return l
 
     def call_plugin(self, plugin, methname, kwargs):
         return kwargs
 
 def varnames(func):
+    try:
+        return func._varnames
+    except AttributeError:
+        pass
     if not inspect.isfunction(func) and not inspect.ismethod(func):
         func = getattr(func, '__call__', func)
     ismethod = inspect.ismethod(func)
     rawcode = py.code.getrawcode(func)
     try:
-        return rawcode.co_varnames[ismethod:rawcode.co_argcount]
+        x = rawcode.co_varnames[ismethod:rawcode.co_argcount]
     except AttributeError:
-        return ()
+        x = ()
+    py.builtin._getfuncdict(func)['_varnames'] = x
+    return x
 
 class HookRelay:
     def __init__(self, hookspecs, pm, prefix="pytest_"):

_pytest/helpconfig.py

 import py
 import pytest
 import inspect, sys
+from _pytest.core import varnames
 
 def pytest_addoption(parser):
     group = parser.getgroup('debugconfig')
                 fail = True
         else:
             #print "checking", method
-            method_args = getargs(method)
-            #print "method_args", method_args
+            method_args = list(varnames(method))
             if '__multicall__' in method_args:
                 method_args.remove('__multicall__')
             hook = hooks[name]
-            hookargs = getargs(hook)
+            hookargs = varnames(hook)
             for arg in method_args:
                 if arg not in hookargs:
                     Print("argument %r not available"  %(arg, ))
     return name == "pytest_plugins" or \
            name.startswith("pytest_funcarg__")
 
-def getargs(func):
-    args = inspect.getargs(py.code.getrawcode(func))[0]
-    startindex = inspect.ismethod(func) and 1 or 0
-    return args[startindex:]
-
 def collectattr(obj):
     methods = {}
     for apiname in dir(obj):
             return self._location
         except AttributeError:
             location = self.reportinfo()
-            fspath = self.session.fspath.bestrelpath(location[0])
+            # bestrelpath is a quite slow function
+            cache = self.config.__dict__.setdefault("_bestrelpathcache", {})
+            try:
+                fspath = cache[location[0]]
+            except KeyError:
+                fspath = self.session.fspath.bestrelpath(location[0])
+                cache[location[0]] = fspath
             location = (fspath, location[1], str(location[2]))
             self._location = location
             return location
         if "xfail" in rep.keywords:
             return rep
         # we assume that the above execute() suspended capturing
-        tw = py.io.TerminalWriter()
+        # XXX we re-use the TerminalReporter's terminalwriter
+        # because this seems to avoid some encoding related troubles
+        # for not completely clear reasons.
+        tw = item.config.pluginmanager.getplugin("terminalreporter")._tw
         tw.line()
         tw.sep(">", "traceback")
         rep.toterminal(tw)