[TIP] Test doubles for Python standard library HTTP classes
me at the-compiler.org
Thu Aug 6 02:37:48 PDT 2015
* Ben Finney <ben+python at benfinney.id.au> [2015-08-06 18:41:24 +1000]:
> What standard Python library is there to make test doubles of
> ‘httplib.HTTPConnection’ and ‘urllib2.HTTPBasicAuthHandler’ and so on?
Is this standard as in stdlib, or standard as in "widely used"?
> There are some libraries that provide a much higher-level API, but I
> need to provide double behaviour at the level this code expects, i.e. at
> the level of the API provided by ‘httplib’ and ‘urllib2’ classes.
Are you thinking of things like VCR.py or HTTPretty here?
Because that's what came to my mind first.
> What standard code libraries provide classes which make it easy to
> double the behaviour of ‘httplib’ classes and ‘urllib2’ classes, etc.
> for test cases?
As others already mentioned, maybe you just want to use unittest.mock
or the backported mock.
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 819 bytes
Desc: not available
More information about the testing-in-python