[issue36871] Misleading error from unittest.mock's assert_has_calls
Samuel Freilich
report at bugs.python.org
Wed Sep 11 15:07:16 EDT 2019
Samuel Freilich <sfreilich at google.com> added the comment:
This is still not totally fixed. This solves the underlying error with method specs, but not the bug that was causing the error-swallowing in assert_has_calls:
https://github.com/python/cpython/blob/ee536b2020b1f0baad1286dbd4345e13870324af/Lib/unittest/mock.py#L2216
expected = [self._call_matcher(c) for c in calls]
cause = expected if isinstance(expected, Exception) else None
isinstance(expected, Exception) is never true, because expected is always a list. It should instead be:
cause = next((e for e in expected if isinstance(e, Exception)), None)
----------
nosy: +sfreilich
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36871>
_______________________________________
More information about the Python-bugs-list
mailing list