How to doctest if __name__ already used?

Jay Parlar jparlar at cogeco.ca
Sun May 7 10:22:55 EDT 2006


On May 5, 2006, at 10:33 PM, Leo Breebaart wrote:

> I have a simple question (I hope), but one I'd love to get some
> feedback on in case I am missing something obvious:
>
> If I have a Python script that is executable, and therefore
> already uses '''if __name__ == "__main__"''' to call a function
> of its own, what is then the easiest yet still most Pythonic way
> to run doctest on the docstrings in the file?
>
> Trigger doctest.testmod() via a "--test" command-line option, is
> what I'm thinking. But is that really the best way?
>

If it is just a single standalone script, then yeah, do it that way. 
Once your program becomes a few files though, you might want a separate 
"test" file that runs doctest.testmod on each of them.

Jay P.




More information about the Python-list mailing list