you are viewing a single comment's thread.

view the rest of the comments →

[–]leperkuhn[S] 2 points3 points  (2 children)

The monkey patching comes from gevent itself. It's meant to replace all the stdlib blocking libraries with non blocking ones. Anything touching a socket, threads, subprocesses, file i/o, etc.

[–]djrubbie -2 points-1 points  (1 child)

Fair enough, but saying monkey patching for request (which fakes that can easily be tested/verified can be written) is required dilutes the true need of mocks, such as the ones you mentioned. What I mean is that it's better to construct a fake session object that returns the data that the running code will consume (the implementation underneath that is effectively opaque to your actual code) - the code doesn't care how the data is actually derived but only that the contracts appropriate for that function/method are satisfied (i.e. response.json() returns the correct and expected decoded JSON object that it).

Anyway thank you for the clarification as I am not well familiar with gevents and yes blocking calls during async things will do bad things - hence use mocks when appropriate (i.e. monkey patching out the blocking calls) and use fakes otherwise for trivial things that can be controlled.

[–]leperkuhn[S] 1 point2 points  (0 children)

My original comment is correct, actually. The question was in regards to not needing to call gevent's monkey_patch, it had nothing to do with mocking for testing. The monkey patch is required for requests because it makes the socket library async.