[Python-ideas] start, test, init

Terry Reedy tjreedy at udel.edu
Sun Dec 1 23:16:05 CET 2013


On 12/1/2013 7:45 AM, spir wrote:

> === why test? ===
>
> If you practice testing (by code), you know why. Nearly all of my
> modules end up ending with:
>
> # ===   t e s t   =======================
>
> def test_abc ():
>      ...
> def test_def ():
>      ...
> def test_ghi ():
>      ...
> ...
> def test ():
>      test_abc()
>      test_def()
>      test_ghi()
>      ...
> if __name__ == '__main__':
>      test()

The style above is obsolete.  The older test.regrtest module (private, 
intended for CPython test suite only) required a test_main function in 
which one collected together the test classes, etc, but one might forget 
something. The newer unittest module does the test discovery for us, so 
no master test function is needed. Just put
unittest.main() at the bottom instead of test(). Much easier.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list