From 80eb9a14bcc9ba20afb2d8f591d8de33582bdcd5 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Wed, 29 Mar 2017 13:22:11 -0400 Subject: [PATCH] Eliminate "during the above exception" in py3 This supports Python 2 and Python 3, and dramatically reduces the number of lines that show up in tracebacks in Python 3. --- pytest_mock.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pytest_mock.py b/pytest_mock.py index f952710..d1be949 100644 --- a/pytest_mock.py +++ b/pytest_mock.py @@ -172,6 +172,7 @@ def mock(mocker): def assert_wrapper(__wrapped_mock_method__, *args, **kwargs): __tracebackhide__ = True + err = None try: __wrapped_mock_method__(*args, **kwargs) except AssertionError as e: @@ -180,7 +181,9 @@ def assert_wrapper(__wrapped_mock_method__, *args, **kwargs): actual_args, actual_kwargs = __mock_self.call_args assert actual_args == args[1:] assert actual_kwargs == kwargs - raise AssertionError(*e.args) + err = e + if err is not None: + raise AssertionError(*err.args) def wrap_assert_not_called(*args, **kwargs):