New issue 697: Support for the Michele Simionato's 'decorator' module. https://bitbucket.org/pytest-dev/pytest/issue/697/support-for-the-michele-simionatos
Vladislav Turbanov: I'm getting the following error, while using the Simionato's useful 'decorator' module https://pypi.python.org/pypi/decorator , which helps decorators preseve the original wrapped function signature. ``` #!bash INTERNALERROR> File "P:/msys64/mingw64/lib/python2.7/site-packages/_pytest/runner.py", line 217, in pytest_runtest_makereport INTERNALERROR> style=item.config.option.tbstyle) INTERNALERROR> File "P:/msys64/mingw64/lib/python2.7/site-packages/_pytest/python.py", line 593, in _repr_failure_py INTERNALERROR> style=style) INTERNALERROR> File "P:/msys64/mingw64/lib/python2.7/site-packages/_pytest/main.py", line 394, in _repr_failure_py INTERNALERROR> return excinfo.value.formatrepr() INTERNALERROR> File "P:/msys64/mingw64/lib/python2.7/site-packages/_pytest/python.py", line 1489, in formatrepr INTERNALERROR> lines, _ = inspect.getsourcelines(function) INTERNALERROR> File "P:/msys64/mingw64/lib/python2.7/inspect.py", line 690, in getsourcelines INTERNALERROR> lines, lnum = findsource(object) INTERNALERROR> File "P:/msys64/mingw64/lib/python2.7/inspect.py", line 538, in findsource INTERNALERROR> raise IOError('could not get source code') INTERNALERROR> IOError: could not get source code ``` The solution to the problem is here: http://micheles.googlecode.com/hg/decorator/documentation.html#getting-the-source-code The decorator's functions have a special member `__wrapped__` , which can be used to get the source code. So the following change in the `pytest/python.py:1489` file can eliminate the error. ``` #!python try: lines, _ = inspect.getsourcelines(function) except Exception, e: # Try to handle the Michele Simionato's decorator case. if hasattr(function, '__wrapped__'): lines, _ = inspect.getsourcelines(function.__wrapped__) else: raise e ``` I've also noticed, that you are already using this techinque in the same `python.py` file. Maybe, it is the way to get the source lines. Your technique is: ``` #!python while hasattr(realfunction, "__wrapped__"): realfunction = realfunction.__wrapped__ ``` _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit