classification
Title: Mock(spec=spec) has no effect
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: davidszotten, michael.foord
Priority: normal Keywords:

Created on 2016-01-28 14:08 by davidszotten, last changed 2016-01-28 16:17 by davidszotten. This issue is now closed.

Messages (3)
msg259130 - (view) Author: David Szotten (davidszotten) * Date: 2016-01-28 14:08
Unless i misunderstand the docs, i would expect `Mock(foo)` to have the same effect as `create_autospec(foo)`, but that doesn't appear to be the case:

>>> m1 = mock.Mock(spec=lambda: None)
>>> m2 = mock.create_autospec(spec=lambda: None)
>>> m1(1)
<Mock name='mock()' id='4377526960'>
>>> m2(1)
# snip
TypeError: too many positional arguments
msg259142 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2016-01-28 15:44
create_autospec and Mock(spec=spec) are very different. Mock(spec=spec) creates a mock object with the same *attributes* as the original. It does not create functions like create_autospec can.
msg259145 - (view) Author: David Szotten (davidszotten) * Date: 2016-01-28 16:17
thanks, and apologies for the noise
History
Date User Action Args
2016-01-28 16:17:56davidszottensetmessages: + msg259145
2016-01-28 15:44:14michael.foordsetstatus: open -> closed
resolution: not a bug
messages: + msg259142

stage: resolved
2016-01-28 15:04:02SilentGhostsetnosy: + michael.foord
2016-01-28 14:08:17davidszottencreate