Skip to content
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

Traceback entries of a chained exception are filtered in importorskip #1485

Closed
roolebo opened this issue Mar 27, 2016 · 1 comment
Closed

Comments

@roolebo
Copy link
Contributor

roolebo commented Mar 27, 2016

importorskip attempts to perform an import and then raises Skipped exception via skip function which has __tracebackhide__ attribute set to True.

This caused the exception in test_importorskip when I added handling of chained exceptions(#1467):

_______________________ test_importorskip _______________________

monkeypatch = <_pytest.monkeypatch.monkeypatch object at 0x110a1e2e8>

    def test_importorskip(monkeypatch):
        importorskip = pytest.importorskip
        def f():
            importorskip("asdlkj")
        try:
            sys = importorskip("sys")  # noqa
            assert sys == py.std.sys
            #path = pytest.importorskip("os.path")
            #assert path == py.std.os.path
            excinfo = pytest.raises(pytest.skip.Exception, f)
>           path = py.path.local(excinfo.getrepr().reprcrash.path)

testing/test_runner.py:502:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
_pytest/_code/code.py:418: in getrepr
    return fmt.repr_excinfo(self)
_pytest/_code/code.py:609: in repr_excinfo
    reprtraceback = self.repr_traceback(excinfo)
_pytest/_code/code.py:585: in repr_traceback
    last = traceback[-1]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = [], key = -1

    def __getitem__(self, key):
>       val = super(Traceback, self).__getitem__(key)
E       IndexError: list index out of range

_pytest/_code/code.py:289: IndexError

The exception is raised because the traceback entry in the original exception is filtered (because of __tracebackhide__ local variable set to True).

roolebo added a commit to roolebo/pytest that referenced this issue Mar 27, 2016
@nicoddemus
Copy link
Member

Thanks! Closing as duplicate of #905.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants