[issue30541] Add restricted mocks to the python unittest mocking framework

Mario Corchero report at bugs.python.org
Wed Jun 21 18:15:41 EDT 2017


Mario Corchero added the comment:

Whilst I agree that using spec can be used for a similar purpose and I did not know about being able to do nested definitions via the arguments (the **{"method1.return_value": 1}, really cool!) I find the idea of allowing users to halt the mock generation really useful. It is much less disruptive and feels more natural.

Compare:
>>> inner_m = Mock(spec=["method2"], **{"method2.return_value": 1})
>>> m = Mock(spec=["method1"], **{"method1.return_value": inner_m})

with: 
>>> m = mock.Mock()
>>> m.method1().method2() = 1
>>> mock.seal(m)


In brief, seal allows users to just add the method to their existing workflow where they use generic mocks. Moreover, it is extremely user friendly, many of the developers that struggle with the mocking module found seal really helpful.

----------

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


More information about the Python-bugs-list mailing list