[TIP] Test doubles for Python standard library HTTP classes

Laura Creighton lac at openend.se
Thu Aug 6 02:33:18 PDT 2015


In a message of Thu, 06 Aug 2015 18:41:24 +1000, Ben Finney writes:
>Howdy all,
>
>What standard Python library is there to make test doubles of
>‘httplib.HTTPConnection’ and ‘urllib2.HTTPBasicAuthHandler’ and so on?
>
>I have a code base (Python 2 code) which performs HTTP sessions using
>the various HTTP-level classes in the standard library.
>
>Testing this code will be made much easier if I can create numerous test
>doubles with pre-determined behaviour and instrumentation for later
>inspection, to allow the functions I'm testing to interact with those
>doubles instead of the real thing.

There is a backport of https://docs.python.org/3/library/unittest.mock.html
as https://pypi.python.org/pypi/mock

Does that count as 'Standard Python library' enough for you?

Laura




More information about the testing-in-python mailing list