Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95076

Test doubles for Python standard library HTTP classes

From Ben Finney <ben+python@benfinney.id.au>
Subject Test doubles for Python standard library HTTP classes
Date 2015-08-06 18:32 +1000
Newsgroups comp.lang.python
Message-ID <mailman.1272.1438849997.3674.python-list@python.org> (permalink)

Show all headers | View raw


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[0] 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 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.

What standard code libraries provide classes which make it easy to
double the behaviour of ‘httplib’ classes and ‘urllib2’ classes, etc.
for test cases?


[0] Test double <URL:http://xunitpatterns.com/Test%20Double.html> is a
more general term covering all of stubs, fakes, spies, mocks, etc. to
double specifically as a fixture in a test case.

-- 
 \      “The most merciful thing in the world… is the inability of the |
  `\        human mind to correlate all its contents.” —Howard Philips |
_o__)                                                        Lovecraft |
Ben Finney

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Test doubles for Python standard library HTTP classes Ben Finney <ben+python@benfinney.id.au> - 2015-08-06 18:32 +1000

csiph-web