* Steven D'Aprano <[email protected]> [2015-07-14 23:41:56 +1000]: > On Tue, Jul 14, 2015 at 02:06:14PM +0200, Dima Tisnek wrote: > > https://bugs.python.org/issue21238 introduces detection of > > missing/misspelt mock.assert_xxx() calls on getattr level in Python > > 3.5 > > > > Michael and Kushal are of the opinion that "assret" is a common typo > > of "assert" and should be supported in a sense that it also triggers > > AttributeError and is not silently ignored like a mocked user > > attribute. > > > > I disagree > > I must admit I don't use mock so don't quite understand what is going on > in this bug report.
Without using spec/autospec, a mock (by design) supports calling any
method on itself, which returns another mock:
>>> m = mock.Mock()
>>> m.eggs()
<Mock name='mock.eggs()' id='140373912833384'>
>>> m.bacon()
<Mock name='mock.bacon()' id='140373910240616'>
However, it also has some special methods to see if it has been
called:
>>> m.assert_called_with()
[...]
AssertionError: Expected call: mock()
Not called
Now because of that, if you do a typo, you won't notice in a test:
>>> m.assert_caled_with()
<Mock name='mock.assert_caled_with()' id='140373910240672'>
With the patch, an AttributeError is raised if you call something
starting with assert or assret instead.
Florian
--
http://www.the-compiler.org | [email protected] (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
pgpNFVsIA898p.pgp
Description: PGP signature
_______________________________________________ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
