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: unittest.mock.Mock should not allow you to use non-existent assert methods
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: Dima.Tisnek, John Allison, kushal.das, michael.foord, python-dev
Priority: normal Keywords: patch

Created on 2014-04-15 15:51 by michael.foord, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue21238.patch kushal.das, 2014-04-16 16:00 Patch with docs and test changes. review
Messages (7)
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) (Python triager) Date: 2014-04-16 18:06
New changeset e4ee0b15cc4f by Kushal Das in branch 'default':
Closes Issue 21238: New keyword argument `unsafe` to Mock.
http://hg.python.org/cpython/rev/e4ee0b15cc4f
msg246689 - (view) Author: Dima Tisnek (Dima.Tisnek) * Date: 2015-07-13 12:07
What is this **assret** spelling?

I can't a reference to this spelling anywhere else in the codebase, let alone any docs other that this special kwarg.

It seems intentional.

Was that a joke?
Or something I should know?
msg246690 - (view) Author: Kushal Das (kushal.das) * (Python committer) Date: 2015-07-13 12:16
It is a typing mistake many people make. We just want to catch those as otherwise mock will silently pass those.
msg246836 - (view) Author: John Allison (John Allison) Date: 2015-07-16 22:51
That probably IS a joke. Why not fix the underlying issue instead?
History
Date User Action Args
2022-04-11 14:58:01adminsetgithub: 65437
2015-07-16 22:51:51John Allisonsetnosy: + John Allison
messages: + msg246836
2015-07-13 12:16:38kushal.dassetmessages: + msg246690
2015-07-13 12:07:42Dima.Tisneksetnosy: + Dima.Tisnek
messages: + msg246689
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