[Twisted-Python] Trial & the mock library

Jonathan Lange jml at mumak.net
Thu Jul 25 08:40:13 MDT 2013


On Thu, Jul 25, 2013 at 3:25 PM, James Broadhead
<jamesbroadhead at gmail.com>wrote:

> I very quickly ran into a problem where I mistakenly returned a Mock() in
> the place of a deferred, causing the asserts in callbacks to not be called,
> and for the test to spuriously pass.
>
> A slightly more believable example:
> == myclass.py ==
> def some_function(...):
>   d = self.authenticate()
>   d.addCallback(foo) # foo never called
>   d.addErrback(bar) # bar never called
>   return d
>
> == test_myclass.py ==
> def setUp(self):
>   self.resource.authenticate = Mock(return_value=Mock())
>
>
Why not use patch and replace it with lambda: defer.succeed(None)?

jml
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20130725/0b5e771e/attachment.html>


More information about the Twisted-Python mailing list