This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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@gmail.com, michael.foord
Priority: normal Keywords:

Created on 2016-01-28 14:08 by davidszotten@gmail.com, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg259130 - (view) Author: David Szotten (davidszotten@gmail.com) * 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@gmail.com) * Date: 2016-01-28 16:17
thanks, and apologies for the noise
History
Date User Action Args
2022-04-11 14:58:26adminsetgithub: 70420
2016-01-28 16:17:56davidszotten@gmail.comsetmessages: + 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:17davidszotten@gmail.comcreate