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

Mario Corchero report at bugs.python.org
Thu Jun 1 17:00:59 EDT 2017


Mario Corchero added the comment:

Sample implementation using the new class:
https://github.com/mariocj89/cpython/commit/2f13963159e239de041cd68273b9fc4a2aa778cd

Sample implementation using the new function to seal existing mocks:
https://github.com/mariocj89/cpython/commit/9ba039e3996f4bf357d4827123e0b570d84f5bb6

Happy to submit a PR if the idea is accepted.

The only benefit I see from the using a separate class is that you will be able to do:

>>> m = mock.SealedMock()
>>> m.important_attr = 42
>>> m.freeflow_attribute = mock.Mock()
>>> mock.seal(m)

which will allow to define "subparts of the mock" without the sealing.

That said I still prefer the function implementation as it looks much nicer (credit to Victor Stinner for the idea)

----------

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


More information about the Python-bugs-list mailing list