1

What widely-used Python library is there to make test doubles of the behaviour of low-level HTTP APIs from the Python standard library?

I have a code base (Python 2 code) which performs HTTP sessions using the various HTTP-level classes in the standard library: httplib.HTTPConnection and urllib2.HTTPBasicAuthHandler and so on.

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.

Mocking the API is no problem, of course; the standard mock library makes that easy. What is needed here, though, is to pre-set specific responses at specific points during the HTTP session, without duplicating the rest of the low-level protocol implementation.

By “widely-known”, I'm hoping that the library will already be available in OS package repositories. Requiring a package from a third party would be a significant cost for this project, so it would help a lot if it's already packaged and in Debian.

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

bignose
  • 24,957
  • 12
  • 70
  • 100

0 Answers0