[New-bugs-announce] [issue24758] unittest.mock.Mock's new "unsafe" feature needs a better error message

Randy Syring report at bugs.python.org
Thu Jul 30 21:07:05 CEST 2015

New submission from Randy Syring:

In issue http://bugs.python.org/issue21238 a feature was introduced to help prevent false-positive test cases by throwing an AttributeError whenever a non-existent method prefixed with "assert_" is used on a mock object.

I had mock objects with legitimate "assert_*" methods that had been working for some time.  My tests included calls like:


My tests started failing unexpectedly and it took me HOURS to figure out that I had a new mock version installed.  Those hours could have been turned into seconds my simply giving a better error message, something like:

AttributeError: you used "assert_in_status" but that method is not a valid Mock assert method.  Please check your spelling.  If this was not a typing mistake, you can use the `unsafe` keyword argument to the Mock instance to turn this validation check off.  See https://mock-docs...org/ for more details.

components: Library (Lib)
messages: 247690
nosy: Randy Syring
priority: normal
severity: normal
status: open
title: unittest.mock.Mock's new "unsafe" feature needs a better error message
type: behavior
versions: Python 3.5

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list