Toplevel "test()" functions in standard library

Rob Hooft rob at hooft.net
Wed Jul 19 03:02:37 EDT 2000


In the standard library there is about 20 modules with the construction:

------------------------------------------
[module definitions]

def test():
    [testing code or general main program]

if __name__=="__main__":
    test()
------------------------------------------

Wouldn't it be better to move the test() definition inside the if
statement in these cases, to prevent name space pollution? Note that
the routines are not called "_test()", so they will be imported by a
"from ... import *" (There are other modules with a _test() definition
as well).

Even worse: the test() routine might have severe side effects:
e.g. base64.test() will block waiting for data from stdin...

Going one step further: Should all of these "test()" and "_test()"
routines be in the code library at all, even now that we have a
complete test engine?

I will submit an example to the SourceForge patch manager.

Rob
-- 
=====   rob at hooft.net          http://www.hooft.net/people/rob/  =====
=====   R&D, Nonius BV, Delft  http://www.nonius.nl/             =====
===== PGPid 0xFA19277D ========================== Use Linux! =========



More information about the Python-list mailing list