[issue37972] unittest.mock.call does not chain __getitem__ to another _Call object

blhsing report at bugs.python.org
Wed Aug 28 16:33:01 EDT 2019


New submission from blhsing <blhsing at gmail.com>:

As reported on StackOverflow:
https://stackoverflow.com/questions/57636747/how-to-perform-assert-has-calls-for-a-getitem-call

The following code would output: [call(), call().foo(), call().foo().__getitem__('bar')]

from unittest.mock import MagicMock, call
mm = MagicMock()
mm().foo()['bar']
print(mm.mock_calls)

but trying to use that list with mm.assert_has_calls([call(), call().foo(), call().foo().__getitem__('bar')]) would result in:

TypeError: tuple indices must be integers or slices, not str

----------
components: Library (Lib)
messages: 350688
nosy: Ben Hsing
priority: normal
severity: normal
status: open
title: unittest.mock.call does not chain __getitem__ to another _Call object
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37972>
_______________________________________


More information about the Python-bugs-list mailing list