News for hackers. Stuff that matters.
Re:Mocking Python Requests with Responses by andrewsomething on Sunday November 23, 2014 @12:59PM (#8649350)
I'm evaluating some different solutions to this problem and would love to hear from anyone who has experience with both this and HTTPretty.
Re:Mocking Python Requests with Responses by droope on Sunday November 23, 2014 @01:28PM (#8649425)
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/blob/master/tests/base_...

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...

This one is useful for adding responses.activate to all methods in a class: https://github.com/droope/droopescan/blob/2cf3f9fd076124e874...

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

Re:Mocking Python Requests with Responses by florentx on Sunday November 30, 2014 @04:16PM (#8678128)
I've evaluated some solutions recently. I like Responses, because its API is simple and easy to use.

However we are using directly the Urllib3 library in our code, so I needed to adapt it to mock Urllib3 instead of Requests.

I've published the package: https://github.com/florentx/urllib3-mock

It can be used either with Urllib3 or Requests.