unittest: collecting tests from many modules?

George Sakkis gsakkis at rutgers.edu
Sun Jun 26 22:16:59 EDT 2005


"Robert Brewer" <fumanchu at amor.org> wrote:

> Anyway, use normal os.walk() calls to gather the files which start with
> "test_"; then use the TestLoader.loadTestsFromName method to instruct
> unittest to test them as a group.

Hi Robert,

this makes much more sense; os.walk and TestLoader.loadTestsFromName
improve the readability of the code significantly. I rewrote almost
from scratch my test script
(http://rafb.net/paste/results/ekTqAV72.html) and it works fine, with
one exception: it fails on test files that run unittest.main() with
non-empty argument list. In my case, some tests define a suite as
defaultTest in unittest.main. The easiest (if not the only) way to run
the unittest with the specified arguments is through execfile() (after
messing with sys.modules to rebind __main__ for each file).

By the way, there would be no need for me specifying a defaultTest if
unittest.main() was looking also for TestSuites in addition to
TestCases within each module. Is this a design choice ?

Regards,
George




More information about the Python-list mailing list