Mercurial > hg > mercurial-crew
changeset 22564:9599e86159ac
heredoctest: use the same dict for local/global contexts as in doctest
In order to mimic module-level evaluation, globals and locals should be the
same object, so doctest does not pass separate locals dict.
https://docs.python.org/2.7/reference/simple_stmts.html#exec
This fixes NameError in the following example:
>>> import foo
>>> def bar():
... foo # must exist in globalvars
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 28 Sep 2014 14:15:43 +0900 (2014-09-28) |
parents | 8cc5e673cac0 |
children | 8d45a42b0c0f |
files | tests/heredoctest.py tests/test-unified-test.t |
diffstat | 2 files changed, 6 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/heredoctest.py +++ b/tests/heredoctest.py @@ -1,7 +1,6 @@ import sys globalvars = {} -localvars = {} lines = sys.stdin.readlines() while lines: l = lines.pop(0) @@ -14,6 +13,6 @@ snippet += "\n" + l[4:] c = compile(snippet, '<heredoc>', 'single') try: - exec c in globalvars, localvars + exec c in globalvars except Exception, inst: print repr(inst)