[New-bugs-announce] [issue23310] MagicMock constructor configuration fails for magic methods

berdario report at bugs.python.org
Sat Jan 24 18:20:39 CET 2015


New submission from berdario:

I guess this should be expected... too much magic :P

>>> from unittest.mock import MagicMock
>>> MagicMock(**{'__hash__.return_value': "FIXME"})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/qlvbf3n3y34idxcgwwhsi9pq26v28q99-python3-3.4.2/lib/python3.4/unittest/mock.py", line 1772, in __init__
    _safe_super(MagicMixin, self).__init__(*args, **kw)
  File "/nix/store/qlvbf3n3y34idxcgwwhsi9pq26v28q99-python3-3.4.2/lib/python3.4/unittest/mock.py", line 881, in __init__
    _spec_state, _new_name, _new_parent, **kwargs
  File "/nix/store/qlvbf3n3y34idxcgwwhsi9pq26v28q99-python3-3.4.2/lib/python3.4/unittest/mock.py", line 410, in __init__
    self.configure_mock(**kwargs)
  File "/nix/store/qlvbf3n3y34idxcgwwhsi9pq26v28q99-python3-3.4.2/lib/python3.4/unittest/mock.py", line 560, in configure_mock
    setattr(obj, final, val)
AttributeError: 'method-wrapper' object has no attribute 'return_value'


The same happens with e.g. __str__

>>> m.configure_mock(**{'__hash__.return_value': 1})

works just fine, instead

----------
components: Library (Lib)
messages: 234623
nosy: berdario
priority: normal
severity: normal
status: open
title: MagicMock constructor configuration fails for magic methods
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23310>
_______________________________________


More information about the New-bugs-announce mailing list