python unittest question

Paul Lussier p.lussier at comcast.net
Tue Apr 28 19:46:57 EDT 2009


Is anyone here familiar with unit testing in python using the unittest
module?  If so, I'm rather stumped on something.

I have a directory with several seperate unit test suites

  $ ls testcases/
  foo_t.py   bar_t.py   baz_t.py

The _t is a local convention indicating this file is a suite of unit
tests for module name which precedes the '_t'.

Currently I run each moduld manually as:
  $ python foo_t.py
  Test foo() method. ... ok
  ---------------
  Ran 1 test in 0.027s

  OK

But I'd really like a way to do a couple things:
  1. run all tests in all suites
  2. run any given test or set of tests within a single suite.

Obviously I can already accomplish #1 with a crude shell script:

  $ for i in *_t.py ; do python $i; done

And I believe there's a way to get #2 as well, but I'm not sure what it is.
Ideally, I'd like a single python script which accomplishes both:

 $ runtests.py                         # would run all tests in all suites
 $ runtests.py  --suite=foo            # would run all tests in foo_t1.py
 $ runtests.py  --suite=foo --test=Bar # would run the foo_t1.testBar() test

Now, the caveat is that I should be able to create testcases/fii_t.py
and then instantly run 'runtests.py' and it should automagically pick
up the new fii_t.py and run all it's tests without me having to modify
runtests.py.

Any ideas ? Thanks.
-- 
Seeya,
Paul


More information about the gnhlug-discuss mailing list