Python Mock Autospec vs Spec

Trying to wrap my head around the difference between Spec and Autospec. They seem to be about the same. In particular, if you look at the mock.patch decoder.

Can someone explain when to use which one?

http://www.voidspace.org.uk/python/mock/patch.html

+4
source share
1 answer

specused as a template for your mock object. According to the documentation :

If you use the spec or spec_set arguments, then only the magic methods that exist in the specification will be created.

, -, , . :

. spec , , spec, AttributeError.

autospec patch spec MagicMock. :

autospec = True, spec .

0

Source: https://habr.com/ru/post/1655137/


All Articles