[TIP] Test doubles for Python standard library HTTP classes

Florian Bruhin 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[1] or HTTPretty[2] here?
Because that's what came to my mind first.

[1] https://pypi.python.org/pypi/vcrpy
[2] https://github.com/gabrielfalcao/HTTPretty

> 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
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20150806/0b22954b/attachment.pgp>

More information about the testing-in-python mailing list