Discussion:
[issue25597] unittest.mock does not wrap dict objects correctly
Darragh Bailey
2015-11-10 17:02:38 UTC
Permalink
New submission from Darragh Bailey:

Both unittest.mock and the backported release for earlier pythons don't appear to support mocking of dictionary objects.

Specifically I'm expecting that any of the methods used to test for membership, or get items from a mock object wrapping a dictionary should succeed. However it appears that MagicMock doesn't appear to support this.

Attached file shows an attempt to use different methods with a wrapped dictionary object where only the '.get()' method appears to work as expected.

----------
files: test-mock-wraps-dict.py
messages: 254453
nosy: Darragh Bailey
priority: normal
severity: normal
status: open
title: unittest.mock does not wrap dict objects correctly
type: behavior
versions: Python 3.5
Added file: http://bugs.python.org/file41001/test-mock-wraps-dict.py

_______________________________________
Python tracker <***@bugs.python.org>
<http://bugs.python.org/issue25597>
_______________________________________
R. David Murray
2015-11-10 23:12:01 UTC
Permalink
R. David Murray added the comment:

Looking at the source, it's not clear that wraps is supported for __ methods, despite what the documentation implies. That is, MagicProxy doesn't seem to look at the wraps information. I suspect it is doable, but it may be an enhancement request rather than a bug fix, I'm not sure.

----------
nosy: +michael.foord, r.david.murray, rbcollins

_______________________________________
Python tracker <***@bugs.python.org>
<http://bugs.python.org/issue25597>
_______________________________________

Loading...