[TIP] Stubbing out httplib2.Http.request

Carl Meyer carl at oddbird.net
Tue Jul 12 13:03:16 PDT 2011


Hi Seth,

On 07/12/2011 12:42 PM, Seth Buntin wrote:
> I am having one heck of a time stubbing out Http.request from httplib2.
>  I currently have five test cases and it takes 13 seconds, even though
> my return_value of Http.request is correct for some reason it seems that
> the request function is still running.
> 
> Here is the gist of my test code:
> 
> https://gist.github.com/5ba6bac1d4efd5cb903b
> 
> I'm using Michael Foord's mock library.  Can anyone help me with this or
> point me in the right direction?

I'm doing this in a current project and its working fine. It's hard to
tell all of what's going on in your case without seeing the module under
test, but one difference I notice between your code and mine is that I
have a module-level instantiation of an Http object in my module under
test, which is used to make requests, and I patch the request method of
that instance rather than the request method of the Http class.

Carl



More information about the testing-in-python mailing list