From: Raymond Hettinger Date: Tue, 27 Jan 2009 10:13:45 +0000 (+0000) Subject: Issue 5021: doctest.testfile should set __name__ X-Git-Tag: v3.0.1~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41db7767455a0c25cb9007d699bef07396a2a4e3;p=thirdparty%2FPython%2Fcpython.git Issue 5021: doctest.testfile should set __name__ --- diff --git a/Lib/collections.py b/Lib/collections.py index c3faa9a44dff..fd13bd8a89c5 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -108,7 +108,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 diff --git a/Lib/doctest.py b/Lib/doctest.py index 74ae79509285..5fa588de1d52 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -837,6 +837,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 = [] @@ -1947,6 +1949,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) diff --git a/Misc/NEWS b/Misc/NEWS index 41feffdb141d..a300fc09bfe9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -104,6 +104,9 @@ Library operator module; use the abstract base classes instead. Also removed the repeat() function; use mul() instead. +- Issue 5021: doctest.testfile() did not create __name__ and + collections.namedtuple() relied on __name__ being defined. + - Issue #1885: distutils. When running sdist with --formats=tar,gztar the tar file was overriden by the gztar one.