[TIP] system testing with Python

holger krekel holger at merlinux.eu
Sun Jan 26 23:33:05 PST 2014


Hi Alfredo,

On Sun, Jan 26, 2014 at 13:43 -0500, Alfredo Deza wrote:
> I am searching for something in Python that will help in system testing. That is, run a command (or a few of them) and allow
> assertions on output or on exit status.
> 
> I’m well aware though that I can do a few calls to subprocess and then inspect stdout/stderr for a match or check the exit status
> with that same object, but I was wondering if there is something out there that might help here.
> 
> The use case is for tests that are done on a storage cluster, so several machines are brought up and a few commands are sent to the cluster with certain expectations, although most of the time we are looking for a non-zero exit status.
> 
> I love py.test, so a plugin for it would be nice, although I wouldn’t mind looking at other things that might help with this kind of testing.
> 
> Any ideas or example would be great!

Apart from scripttest you might want to look into pytest's own tests
which use a "testdir" fixture, defined in _pytest/pytester.py.  It helps
to run pytest as an external command and do assertions about its retcode
and output.  See pytest's tests for how it is used.  It's also a wrapper
around subprocess.

cheers
holger



More information about the testing-in-python mailing list