Skip to content

INTERNALERROR with __tracebackhide__ and empty traceback #905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
philpep opened this issue Jul 30, 2015 · 8 comments
Closed

INTERNALERROR with __tracebackhide__ and empty traceback #905

philpep opened this issue Jul 30, 2015 · 8 comments
Labels
type: bug problem that needs to be addressed

Comments

@philpep
Copy link

philpep commented Jul 30, 2015

Hi,

I don't known if it's a py or a pytest related bug, but i didn't find the project page for py so I submit the issue here.

Consider this test:

import pytest


@pytest.mark.parametrize("param", ["foo"])
def test(param):
    __tracebackhide__ = True
    assert param == "bar"

The test fail as expected but not as expected :)

$ py.test test_bug.py
==== test session starts ====
platform linux2 -- Python 2.7.9, pytest-2.8.0.dev4, py-1.4.30, pluggy-0.3.0
rootdir: /home/phil/src/pytest, inifile: tox.ini
collected 1 items 

test_bug.py

[...]
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 253, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/phil/src/pytest/_pytest/runner.py", line 67, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/home/phil/src/pytest/_pytest/runner.py", line 77, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/home/phil/src/pytest/_pytest/runner.py", line 123, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 249, in _wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "/home/phil/src/pytest/_pytest/skipping.py", line 170, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/pluggy-0.3.0-py2.7.egg/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/phil/src/pytest/_pytest/runner.py", line 226, in pytest_runtest_makereport
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "/home/phil/src/pytest/_pytest/python.py", line 665, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File "/home/phil/src/pytest/_pytest/python.py", line 658, in _repr_failure_py
INTERNALERROR>     style=style)
INTERNALERROR>   File "/home/phil/src/pytest/_pytest/main.py", line 406, in _repr_failure_py
INTERNALERROR>     style=style, tbfilter=tbfilter)
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/py-1.4.30-py2.7.egg/py/_code/code.py", line 412, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/py-1.4.30-py2.7.egg/py/_code/code.py", line 590, in repr_excinfo
INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/py-1.4.30-py2.7.egg/py/_code/code.py", line 577, in repr_traceback
INTERNALERROR>     last = traceback[-1]
INTERNALERROR>   File "/home/phil/venvs/pytest/local/lib/python2.7/site-packages/py-1.4.30-py2.7.egg/py/_code/code.py", line 284, in __getitem__
INTERNALERROR>     val = super(Traceback, self).__getitem__(key)
INTERNALERROR> IndexError: list index out of range

Same issue on 2.7.2 and on master branch (0b83b40)

Thanks

@RonnyPfannschmidt
Copy link
Member

its a pylib bug, by default anything above the test function is cut off, now if you in addition make it filter out the test function, then it helplessly has to resign at the empty traceback

this is a missed condition in py.code

@nicoddemus
Copy link
Member

this is a missed condition in py.code

Should someone report the issue in pylib then?

@nicoddemus nicoddemus added the type: bug problem that needs to be addressed label Jul 30, 2015
@philpep philpep changed the title INTERNALERROR with pytest.mark.parametrize and __tracebackhide__ INTERNALERROR with __tracebackhide__ and empty traceback Jul 30, 2015
@philpep
Copy link
Author

philpep commented Jul 30, 2015

Ok the bug isn't related to pytest.mark.parametrize, I update the title.

A more simple test to reproduce de bug is:

def test():
    __tracebackhide__ = True
    assert False

@nicoddemus
Copy link
Member

Thanks @philpep

@RonnyPfannschmidt
Copy link
Member

we want to merge py.code into py.test since a while now, so i'm ambivalent about it

@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8, 2.8.dev Sep 13, 2015
d42 added a commit to d42/py_soundboard that referenced this issue Sep 18, 2015
@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8.2, 2.8.1 Sep 27, 2015
@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8.2, 2.8.3 Oct 10, 2015
@nicoddemus nicoddemus modified the milestones: 2.8.3, 2.8.4 Nov 23, 2015
@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8.4, 2.8.5 Dec 6, 2015
@RonnyPfannschmidt RonnyPfannschmidt modified the milestones: 2.8.5, 2.8.6 Dec 14, 2015
@nicoddemus
Copy link
Member

@max4t gives a nice suggestion in #1493:

Wouldn't it be useful to print the test body as traceback if it's empty? Instead of printing the pytest_runtest_call body (without tracebackhide) or raising an error (with tracebackhide).

@max4t
Copy link

max4t commented Mar 30, 2016

Here is a workaround i used to print the test body on Python3 (which should work on python2) (see #1493).

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    if call.excinfo:
        traceback = call.excinfo.traceback
        item._prunetraceback(call.excinfo)
        if len(call.excinfo.traceback) > 0:
            call.excinfo.traceback = traceback
        else:
            # Fake frame containing the test
            fakef = lambda: None
            fakef.f_back = None
            fakef.f_code = item.function.__code__
            fakef.f_locals = item.funcargs
            fakef.f_globals = item.function.__globals__
            fakef.f_lineno = fakef.f_code.co_firstlineno
            # Fake traceback with the fake exception at the last line of the test
            faketb = lambda: None
            faketb.tb_frame = fakef
            faketb.tb_lineno = fakef.f_lineno
            faketb.tb_lineno += len(inspect.getsourcelines(fakef.f_code)[0]) - 1 # Last line of the function
            faketb.tb_next = None
            call.excinfo.traceback.__init__(faketb)
    yield

Considering that py.code doesn't have access to the tests, i had to provide a fake traceback so it wouldn't see the difference and still produce an output.

@nicoddemus nicoddemus removed this from the 2.8.6 milestone Jul 9, 2016
@nicoddemus
Copy link
Member

Fixed already. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

4 participants