Author: Antonio Cuni <anto.c...@gmail.com> Branch: py3k Changeset: r53029:e8b1a2d32c9b Date: 2012-02-29 15:30 +0100 http://bitbucket.org/pypy/pypy/changeset/e8b1a2d32c9b/
Log: make sure that we can access the correct locals when evaluating the stmt inside 'raises' with -A diff --git a/pypy/conftest.py b/pypy/conftest.py --- a/pypy/conftest.py +++ b/pypy/conftest.py @@ -201,6 +201,7 @@ if python is None: py.test.skip("Cannot find the default python3 interpreter to run with -A") helpers = r"""if 1: + import sys def skip(message): print(message) raise SystemExit(0) @@ -213,7 +214,8 @@ # it's probably an indented block, so we prefix if True: # to avoid SyntaxError func = "if True:\n" + func - exec(func) + frame = sys._getframe(1) + exec(func, frame.f_globals, frame.f_locals) else: func(*args, **kwargs) except exc as e: diff --git a/pypy/tool/pytest/test/conftest1_innertest.py b/pypy/tool/pytest/test/conftest1_innertest.py --- a/pypy/tool/pytest/test/conftest1_innertest.py +++ b/pypy/tool/pytest/test/conftest1_innertest.py @@ -31,3 +31,7 @@ def test_method(self): assert self.space +def app_test_raise_in_a_closure(): + def f(x): + raises(AttributeError, "x.foo") + f(42) diff --git a/pypy/tool/pytest/test/test_conftest1.py b/pypy/tool/pytest/test/test_conftest1.py --- a/pypy/tool/pytest/test/test_conftest1.py +++ b/pypy/tool/pytest/test/test_conftest1.py @@ -60,3 +60,11 @@ assert "test_code_in_docstring_ignored" in passed[0].nodeid assert "app_test_code_in_docstring_failing" in failed[0].nodeid assert "test_code_in_docstring_failing" in failed[1].nodeid + + def test_raises_inside_closure(self, testdir): + sorter = testdir.inline_run(innertest, '-k', 'app_test_raise_in_a_closure', + '--runappdirect') + passed, skipped, failed = sorter.listoutcomes() + assert len(passed) == 1 + print passed + assert "app_test_raise_in_a_closure" in passed[0].nodeid _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit