I'd avoid monkey patching, it can confuse the programmer as to which module is being used. In a small program it's not a big deal but in large systems it can become an issue.
It makes sense in certain situations. For example, if you're using non-blocking i/o with an event loop (using gevent or similar) then as soon as you have one blocking operation, performance suffers dramatically.
Monkeypatching gevent's socket globally allows you to use libraries and drivers like pymongo off the shelf, and they will be non-blocking by default.
[+] [-] davvid|14 years ago|reply
http://www.voidspace.org.uk/python/mock/mock.html
[+] [-] yyyt|14 years ago|reply
with patch('path.to.object') as my_mock: my_mock.method.return_value = ...
also you can patch a module/class with a function.
[+] [-] halayli|14 years ago|reply
[+] [-] colinmarc|14 years ago|reply
Monkeypatching gevent's socket globally allows you to use libraries and drivers like pymongo off the shelf, and they will be non-blocking by default.
[+] [-] almost|14 years ago|reply
[+] [-] njharman|14 years ago|reply
[+] [-] devy|14 years ago|reply