[Python-Dev] sys.modules["__main__"] in Jython
Skip Montanaro
skip@pobox.com (Skip Montanaro)
Fri, 8 Jun 2001 09:51:27 -0500
Would someone with Jython experience check to see if it interprets
sys.modules["__main__"] in the same manner as Python? I'm interested to see
if doctest's normal usage can be simplified slightly. The doctest
documentation states:
In normal use, end each module M with:
def _test():
import doctest, M # replace M with your module's name
return doctest.testmod(M) # ditto
if __name__ == "__main__":
_test()
I'm wondering if this works for Jython as well as Python:
def _test():
import doctest, sys
return doctest.testmod(sys.modules["__main__"])
if __name__ == "__main__":
_test()
If so, then I think doctest.testmod's signature can be changed to
def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None,
report=1):
with the following extra code added to the start of the function:
if m is None:
import sys
m = sys.modules["__main__"]
That way the most common doctest usage can be changed to
def _test():
import doctest
return doctest.testmod()
if __name__ == "__main__":
_test()
(I ran into a problem with a module that had initialization code that barfed
if executed more than once.)
Of course, these changes are ultimately Tim's decision. I'm just trying to
knock down various potential hurdles.
Thx,
Skip