Issue 5021: doctest.testfile should set __name__

This commit is contained in:
Raymond Hettinger 2009-01-27 10:30:26 +00:00
parent cdc9f2c1d5
commit 8c0cee814f
3 changed files with 8 additions and 1 deletions

View File

@ -103,7 +103,7 @@ def namedtuple(typename, field_names, verbose=False):
# where the named tuple is created. Bypass this step in enviroments where
# sys._getframe is not defined (Jython for example).
if hasattr(_sys, '_getframe'):
result.__module__ = _sys._getframe(1).f_globals['__name__']
result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
return result

View File

@ -844,6 +844,8 @@ class DocTestFinder:
globs = globs.copy()
if extraglobs is not None:
globs.update(extraglobs)
if '__name__' not in globs:
globs['__name__'] = '__main__' # provide a default module name
# Recursively expore `obj`, extracting DocTests.
tests = []
@ -1937,6 +1939,8 @@ def testfile(filename, module_relative=True, name=None, package=None,
globs = globs.copy()
if extraglobs is not None:
globs.update(extraglobs)
if '__name__' not in globs:
globs['__name__'] = '__main__'
if raise_on_error:
runner = DebugRunner(verbose=verbose, optionflags=optionflags)

View File

@ -76,6 +76,9 @@ Core and Builtins
Library
-------
- Issue 5021: doctest.testfile() did not create __name__ and
collections.namedtuple() relied on __name__ being defined.
- Issue #3881: Help Tcl to load even when started through the
unreadable local symlink to "Program Files" on Vista.