diff --git a/py/__init__.py b/py/__init__.py index d16105739..5ff8de317 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -133,6 +133,7 @@ initpkg(__name__, 'code.Frame' : ('./code/frame.py', 'Frame'), 'code.ExceptionInfo' : ('./code/excinfo.py', 'ExceptionInfo'), 'code.Traceback' : ('./code/traceback2.py', 'Traceback'), + 'code.getfslineno' : ('./code/source.py', 'getfslineno'), # backports and additions of builtins 'builtin.__doc__' : ('./builtin/__init__.py', '__doc__'), diff --git a/py/test/pycollect.py b/py/test/pycollect.py index 4c60a4a9b..fe4f99861 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -18,7 +18,6 @@ a tree of collectors and test items that this modules provides:: """ import py from py.__.test.collect import configproperty, warnoldcollect -from py.__.code.source import findsource pydir = py.path.local(py.__file__).dirpath() from py.__.test import funcargs @@ -69,37 +68,21 @@ class PyobjMixin(object): s = ".".join(parts) return s.replace(".[", "[") - def getfslineno(self): + def _getfslineno(self): try: return self._fslineno except AttributeError: pass obj = self.obj - # let decorators etc specify a sane ordering + # xxx let decorators etc specify a sane ordering if hasattr(obj, 'place_as'): obj = obj.place_as - try: - code = py.code.Code(obj) - except TypeError: - # fallback to - fn = (py.std.inspect.getsourcefile(obj) or - py.std.inspect.getfile(obj)) - fspath = fn and py.path.local(fn) or None - if fspath: - try: - _, lineno = findsource(obj) - except IOError: - lineno = None - else: - lineno = None - else: - fspath = code.path - lineno = code.firstlineno - self._fslineno = fspath, lineno - return fspath, lineno + + self._fslineno = py.code.getfslineno(obj) + return self._fslineno def metainfo(self): - fspath, lineno = self.getfslineno() + fspath, lineno = self._getfslineno() modpath = self.getmodpath() return fspath, lineno, modpath @@ -233,7 +216,7 @@ class Class(PyCollectorMixin, py.test.collect.Collector): teardown_class(self.obj) def _getsortvalue(self): - return self.getfslineno() + return self._getfslineno() class Instance(PyCollectorMixin, py.test.collect.Collector): def _getobj(self): @@ -258,7 +241,7 @@ class FunctionMixin(PyobjMixin): """ def _getsortvalue(self): - return self.getfslineno() + return self._getfslineno() def setup(self): """ perform setup for this test function. """ diff --git a/py/test/runner.py b/py/test/runner.py index 384dc644b..9c3c5fa83 100644 --- a/py/test/runner.py +++ b/py/test/runner.py @@ -76,7 +76,7 @@ def forked_run_report(item, pdb=None): return report_process_crash(item, result) def report_process_crash(item, result): - path, lineno = item.getfslineno() + path, lineno = item._getfslineno() longrepr = [ ("X", "CRASHED"), ("%s:%s: CRASHED with signal %d" %(path, lineno, result.signal)),