[New-bugs-announce] [issue5021] doctest.testfile should set __name__, can't use namedtuple
Tom Lynn
report at bugs.python.org
Wed Jan 21 13:23:07 CET 2009
New submission from Tom Lynn <tlynn at users.sourceforge.net>:
This file fails when run with doctest.testfile::
>>> print __name__
__builtin__
>>> print globals()['__name__'] # fails with KeyError: __name__
__builtin__
"__builtin__" is probably not a good value, but more importantly, this
means that you can't use namedtuples in text file doctests, since
namedtuple() inspects the calling frame::
>>> from namedtuple import namedtuple
>>> t = namedtuple('fred', 'x') # fails
(I presume this is the same for "from collections import namedtuple",
but I've not tested with 2.6+.)
A workaround is to add this line at the start of the test::
>>> __name__ = 'test'
----------
components: Library (Lib)
messages: 80322
nosy: tlynn
severity: normal
status: open
title: doctest.testfile should set __name__, can't use namedtuple
type: feature request
versions: Python 2.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5021>
_______________________________________
More information about the New-bugs-announce
mailing list