Skip to content

pytest does not print chained exception for python 3 #1278

Closed
@jettify

Description

@jettify

py.test pytest (2.8.5) does not print chained exceptions, data located in e.__cause__ and e.__context__.

If I execute this little script using python3 (python3 test_exception.py):

def test_x():
    try:
        raise KeyError
    except Exception as e:
        raise RuntimeError from e

if __name__ == '__main__':
    test_x()

I get:

Traceback (most recent call last):
  File "py_test.py", line 4, in test_x
    raise KeyError
KeyError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "py_test.py", line 9, in <module>
    test_x()
  File "py_test.py", line 6, in test_x
    raise RuntimeError from e
RuntimeError

in case of py.test (py.test test_exception.py):

    def test_x():
        try:
            raise KeyError
        except Exception as e:
>           raise RuntimeError from e
E           RuntimeError

py_test.py:6: RuntimeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions