How to doctest if __name__ already used?

L

Leo Breebaart

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?
 
C

Chris Lambacher

Trigger doctest.testmod() via a "--test" command-line option, is
what I'm thinking. But is that really the best way?
That is what I would have suggested.

-Chris
 
J

Jay Parlar

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top