Rest WebService Testing using Python

Roy Smith roy at
Sat Jul 12 15:47:06 CEST 2014

In article <bbdb1f48-9fe8-43af-a765-de5894d38b2d at>,
 neeraj.bakhtani at wrote:

> Hi folks,
> This is Neeraj , I want to develop some standalone python Scripts to Test 
> Rest Webservices i.e. WADL services with endpoints.
> Particularly I need "A script for logging in would pass the xml to the rest 
> api with variables for all the payload fields python"
> So Can Anyone please provide me some sample scripts or tutorials or package 
> that can help me in above Scenario for automating the Rest WebService Testing 
> for me
> I am new to python.So please bear with me..:)
> Thanks in advance

The question you are asking is broad, so I can only make some general 
suggestions.  You've really got two needs here.  One is you need some 
kind of test framework, the other is that you need some way to talk to 
an HTTP server.  Let's attack those one at a time.

Test framework.  Testing is all about writing down a list of things you 
believe to be true, and then exercising the code to verify that they are 
indeed true.  When I do X, I expect Y to happen.  If it does, the test 
passes.  If not, the test fails.  Generally you write a large number of 
these tests, and run them all.

A lot of this is boilerplate.  You need some way to organize all the 
individual tests.  Run them (or perhaps run subsets of them).  Record 
which ones passed or not.  Set up the right environment for each test to 
run, and possibly clean up after each one.  The idea of a test framework 
is that it takes care of most of this for you automatically, letting you 
concentrate on the test logic.

There's a couple of choices for test frameworks.  The standard one that 
comes packaged with Python is unittest 
(  I used to use it a 
lot, but I've come to regard it as somewhat klunky.  Still, it's the 
standard.  If you've used JUnit, it has the advantage that it will feel 
very familiar.

A newer alternative is nose (, which is 
what I mostly use now.  Nose simplifies some things, but sometimes can 
be a bit difficult to understand (the docs can be a bit obtuse in 
places).  The big advantage of nose is it has some very powerful tools 
for running tests in parallel.  If you have a lot of tests that are I/O 
bound, this can seriously reduce the time to run your test suite.

There's also doctest (, 
but for the kind of testing you want to do, it's probably not the right 
tool.  I include it only for completeness.

OK, so now, how to talk to your HTTP service.  That's easy.  You want to 
use requests (  If your web service 
involves persisting state on the client side with cookies, you'll want 
to explore requests' session functionality.

More information about the Python-list mailing list