You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Two tracebacks with assert_wrapper / wrap_assert_has_calls #44
When using assert_has_calls I am seeing two tracebacks, but the first one should not be there?!
Traceback (most recent call last):
File "…/pytest-mock/pytest_mock.py", line 155, in assert_wrapper
__wrapped_mock_method__(*args, **kwargs)
File "/usr/lib64/python3.5/unittest/mock.py", line 824, in assert_has_calls
) from cause
AssertionError: Calls not found.
Expected: […]
Actual: […]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "…/app/tests/test_metrics.py", line 495, in test_handle_missing_values
expected_call(end, 2, None),
File "…/pytest-mock/pytest_mock.py", line 181, in wrap_assert_has_calls
*args, **kwargs)
File "…/pytest-mock/pytest_mock.py", line 157, in assert_wrapper
raise AssertionError(*e.args)
AssertionError: Calls not found.
Expected: […]
Actual: […]
This is with pytest-2.9.2.dev1 and Python 3.5.1.
It looks like the __tracebackhide__ = True trick is not working?!
With mock_traceback_monkeypatch=false I only get the original traceback as expected.
The default exception handler will be modified to report chained
exceptions. The chain of exceptions is traversed by following the
'__cause__' and '__context__' attributes, with '__cause__' taking
priority. In keeping with the chronological order of tracebacks,
the most recently raised exception is displayed last; that is, the
display begins with the description of the innermost exception and
backs up the chain to the outermost exception. The tracebacks are
formatted as usual, with one of the lines:
So if we want to "hide" the fact that we caught and raised the AssertionErroe exception in python 3, we could probably set e.__context__ = None, or maybe e.__suppress_context__ = True is better and more explicit.
Nah, you'll not find the changes in 2; though version 2.5 was the original target for PEP 344, it was superseded by PEP 3134 since it was targeted for Python 3. You can see 3134 mentioned in Python 3 release notes.
@blueyed this happens only with --tb=native right?
@asfaltboy tried your suggestion real quick now but it did not work: inside the except clause in assert_wrapper, e.__context__ is already None. I will investigate this more carefully later, but meanwhile if somebody got another suggestion I'm all ears.
Activity
asfaltboy commentedon May 20, 2016
Although I have not tried using the plugin with python 3 yet, this looks like the "raise .. from .." exception chaining feature which was added in 3.5, to quote the PEP:
So if we want to "hide" the fact that we caught and raised the
AssertionErroeexception in python 3, we could probably sete.__context__ = None, or maybee.__suppress_context__ = Trueis better and more explicit.The-Compiler commentedon May 20, 2016
@asfaltboy you mean 2.5, not 3.5 😉
asfaltboy commentedon May 20, 2016
Nah, you'll not find the changes in 2; though version 2.5 was the original target for PEP 344, it was superseded by PEP 3134 since it was targeted for Python 3. You can see 3134 mentioned in Python 3 release notes.
nicoddemus commentedon May 20, 2016
@blueyed this happens only with
--tb=nativeright?@asfaltboy tried your suggestion real quick now but it did not work: inside the
exceptclause inassert_wrapper,e.__context__is alreadyNone. I will investigate this more carefully later, but meanwhile if somebody got another suggestion I'm all ears.blueyed commentedon May 21, 2016
@nicoddemus
Yeah, I am using
--tb=native.Disable monkey patching "mock" when --tb is set to native