python unittest question
Lloyd Kvam
lkvam at venix.com
Wed Apr 29 08:40:55 EDT 2009
On Tue, 2009-04-28 at 19:46 -0400, Paul Lussier wrote:
> Is anyone here familiar with unit testing in python using the unittest
> module? If so, I'm rather stumped on something.
>
The nosetests module (package probably named python-nose) will do what
you want though it supports a different naming convention for your test
modules.
Essentially it looks for test*.py modules and runs them. It provides
consistent ordering and reasonably smart reporting. You can use command
line options to control essential aspects of your test runs.
Highly recommended.
> 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.
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-653-8139
fax: 320-210-3409
More information about the gnhlug-discuss
mailing list