[Twisted-Python] Adding mock as a test suite dependency

David Reid dreid at dreid.org
Mon Oct 22 13:22:03 EDT 2012


On Mon, Oct 22, 2012 at 9:57 AM, Laurens Van Houtven <_ at lvh.cc> wrote:

> So, mock does have an autospec mode, which is not the default, but does
> result in eg methods undefined on the parent raising AttributeError.
>

It does, but it won't for instance know that for:
    mock_agent = mock.Mock(Agent)

that mock_agent.request should return a thing that looks like a Deferred.
 So you still
end up with a bunch of setup code to enforce return types and things.


> I don't know if there's a way to generate a mock from an interface:
> particularly the fact that interface methods don't have "self" in their
> signature might trip it up.
>

Yeah, this doesn't work at all.  You end up having to always pass a thing
which provides the interface.  Or an unspecified Mock.

Of course, this isn't actually a "verified" Mock.  Because you still have
to specify all the behavior and constructing that behavior by setting
side_effect and return_value is often difficult and confusing.

So though I use mock quite a bit in my personal projects and at work I am
definitely against using it for twisted style tests.  I'd rather see some
energy put into things like a verified fake Request object and a
ResourceTraversingAgent.

-David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20121022/ebb98326/attachment.htm 


More information about the Twisted-Python mailing list