New submission from Tom Lynn <[email protected]>:
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 <[email protected]>
<http://bugs.python.org/issue5021>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com