

Mocking Python Requests with Responses - andrewsomething
http://cramer.io/2014/05/20/mocking-requests-with-responses/

======
rw_grim
I'm still wondering how HTTMock didn't do the job for them... Unfortunately,
comments are closed on that blog, so I guess I'll never know..

------
andrewsomething
I'm evaluating some different solutions to this problem and would love to hear
from anyone who has experience with both this and HTTPretty.

~~~
droope
I personally haven't used httpretty, because of the way it had been
implemented, I thought it would be impossible for it not to cause bugs in my
tests. (Monkey patching socket seems way more complex than patching urllib, or
requests)

I am using responses in the CMS Scanner I am building

[https://github.com/droope/droopescan](https://github.com/droope/droopescan)

[https://github.com/droope/droopescan/blob/master/tests/base_...](https://github.com/droope/droopescan/blob/master/tests/base_http_tests.py)

I did have to create some helper functions in order to make responses easier
to apply to a broad range of tests, those are here:

This one allows you to mock several requests in a more tidy way:
[https://github.com/droope/droopescan/blob/2cf3f9fd076124e874...](https://github.com/droope/droopescan/blob/2cf3f9fd076124e87440d6bb549f254c6dae8654/tests/__init__.py#L100-L106)

This one is useful for adding responses.activate to all methods in a class:
[https://github.com/droope/droopescan/blob/2cf3f9fd076124e874...](https://github.com/droope/droopescan/blob/2cf3f9fd076124e87440d6bb549f254c6dae8654/common/testutils.py#L5-L19)

Overall, it works perfectly (and I've been developing with it for at least
half a year), and supports python 3.

