Program __main__ function

André Malo auch-ich-m at
Tue Mar 13 10:35:43 CET 2007

Ben Finney wrote:

> Ben Finney <bignose+hates-spam at> writes:
>> Now, when I write unit tests for my program (i.e. a Python module
>> designed to be run as a command), it can still be imported safely
>> into my unit tests, and all the code gets covered by test cases
>> except the three-line stanza at the end.
> All I need now is for Python to automatically execute a '__main__'
> function if the module name is '__main__' (which it seems the OP
> expected should happen), and unit test coverage could be 100% :-)

Short hint to go further:
exec file('/usr/lib/python2.4/') in {'__name__': '__main__'}


More information about the Python-list mailing list