classification
Title: Mock functions with autospec don't support assert_called_once, assert_called, assert_not_called
Type: behavior Stage: commit review
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: Yannick Brehon, gregory.p.smith, python-dev
Priority: normal Keywords: patch

Created on 2016-10-06 20:13 by Yannick Brehon, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Files
File name Uploaded Description Edit
fix_autospecced_mock_functions.patch Yannick Brehon, 2016-10-06 20:13 Patch for fixing the issue against head review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (3)
msg278208 - (view) Author: Yannick Brehon (Yannick Brehon) * Date: 2016-10-06 20:13
If one defines a mock for a function, using autospec=True, then the mock will correctly support assert_called_once_with(), among others, but not assert_called_once, assert_called, and assert_not_called.
The attached file contains a fix for the issue.
msg278213 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-10-06 21:32
New changeset 4e39b4e57673 by Gregory P. Smith in branch '3.6':
Fixes issue28380: unittest.mock Mock autospec functions now properly support
https://hg.python.org/cpython/rev/4e39b4e57673

New changeset fca5c4a63251 by Gregory P. Smith in branch 'default':
Issue #28380: unittest.mock Mock autospec functions now properly support
https://hg.python.org/cpython/rev/fca5c4a63251
msg278214 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2016-10-06 21:35
thanks!  I didn't apply the fix to 3.5 (or earlier - those are closed) as it could arguably be seen as adding a new API and there are valid workarounds by asserting on the list of calls directly.
History
Date User Action Args
2017-03-31 16:36:23dstufftsetpull_requests: + pull_request973
2016-10-06 21:35:57gregory.p.smithsetstatus: open -> closed
versions: - Python 3.3, Python 3.4, Python 3.5
messages: + msg278214

resolution: fixed
stage: commit review
2016-10-06 21:32:29python-devsetnosy: + python-dev
messages: + msg278213
2016-10-06 21:10:16gregory.p.smithsetassignee: gregory.p.smith

nosy: + gregory.p.smith
2016-10-06 20:13:19Yannick Brehoncreate