Title: unittest.mock.Mock should not allow you to use non-existent assert methods
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: kushal.das, michael.foord, python-dev
Priority: normal Keywords: patch

Created on 2014-04-15 15:51 by michael.foord, last changed 2014-04-16 18:06 by python-dev. This issue is now closed.

File name Uploaded Description Edit
issue21238.patch kushal.das, 2014-04-16 16:00 Patch with docs and test changes. review
Messages (4)
msg216320 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2014-04-15 15:51
A common problem with unittest.mock.Mock is to mistype an assert method. Because mocks create attributes on demand your test will pass without error.

We should raise an AttributeError if you access any attribute name (that doesn't exist) starting with assert or assret. There should also be a keyword argument allowing you to get the old behaviour if you need it (but this new feature should be on by default).

Will also need docs.
msg216481 - (view) Author: Kushal Das (kushal.das) * (Python committer) Date: 2014-04-16 16:00
Patch with docs and test changes.
msg216518 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2014-04-16 17:50
It needs a NEWS entry, but looks good to me.
msg216534 - (view) Author: Roundup Robot (python-dev) Date: 2014-04-16 18:06
New changeset e4ee0b15cc4f by Kushal Das in branch 'default':
Closes Issue 21238: New keyword argument `unsafe` to Mock.
Date User Action Args
2014-04-16 18:06:58python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg216534

resolution: fixed
stage: needs patch -> resolved
2014-04-16 17:50:21michael.foordsetmessages: + msg216518
2014-04-16 16:00:43kushal.dassetfiles: + issue21238.patch
keywords: + patch
messages: + msg216481
2014-04-15 15:51:18michael.foordcreate