What misspellings / typos are supported in Python?
Not alternate spellings such as is_dir
vs isdir
, nor color
vs colour
but actual wrongly spelt aliases, such as proprety
for property
(which isn't supported).
As of Python 3.5 beta 3 the unittest.mock object now supports assret
standing in for assert
-- note that this is not the keyword assert
, but any attribute of a mock object that matches the regular expression assert.*
or assret.*
.
Some explanation:
When a mock object is created the default for any attribute access is to return a new Mock
, except in one case: if the attribute is one of assert_called_with
, assert_called_once_with
, assert_any_call
, assert_has_calls
, and assert_not_called
, in which case some code is actually run.
The problem is if one forgets the exact name and uses, for example, assert_called
, then instead of code running to check that the mock was called, a new mock is returned instead and the test one wrote passes instead of actually doing the test and possibly failing.
To combat this problem Mock
now raises an AttributeError
if any access is made to an attribute that starts with assert
.
Besides assert
, Mock
will also raise an AttributeError
if any access is made to an attribute that starts with assret
.
If one does not want the extra protection (for assert
and assret
) one can use unsafe=True
when creating the Mock
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With