[pypy-commit] pypy apptest-file: Do assert reinterpretation only inside old-style apptests; fix tests.

rlamy pypy.commits at gmail.com
Sun Apr 15 12:08:18 EDT 2018


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: apptest-file
Changeset: r94337:d719e76c1bc7
Date: 2018-04-15 17:07 +0100
http://bitbucket.org/pypy/pypy/changeset/d719e76c1bc7/

Log:	Do assert reinterpretation only inside old-style apptests; fix
	tests.

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -247,6 +247,10 @@
         BoolOption("newshortcut",
                    "cache and shortcut calling __new__ from builtin types",
                    default=False),
+        BoolOption("reinterpretasserts",
+                   "Perform reinterpretation when an assert fails "
+                   "(only relevant for tests)",
+                   default=False),
 
      ]),
 ])
diff --git a/pypy/tool/pytest/apptest.py b/pypy/tool/pytest/apptest.py
--- a/pypy/tool/pytest/apptest.py
+++ b/pypy/tool/pytest/apptest.py
@@ -44,7 +44,7 @@
         target = self.obj
         if self.config.option.runappdirect:
             return target()
-        space = gettestobjspace()
+        space = gettestobjspace(**{'objspace.std.reinterpretasserts': True})
         filename = self._getdynfilename(target)
         func = app2interp_temp(target, filename=filename)
         print "executing", func
diff --git a/pypy/tool/pytest/objspace.py b/pypy/tool/pytest/objspace.py
--- a/pypy/tool/pytest/objspace.py
+++ b/pypy/tool/pytest/objspace.py
@@ -7,10 +7,10 @@
 
 _SPACECACHE={}
 def gettestobjspace(**kwds):
-    """ helper for instantiating and caching space's for testing.
+    """ helper for instantiating and caching spaces for testing.
     """
     try:
-        config = make_config(option,**kwds)
+        config = make_config(option, **kwds)
     except ConflictConfigError as e:
         # this exception is typically only raised if a module is not available.
         # in this case the test should be skipped
@@ -33,8 +33,9 @@
     config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
     space = make_objspace(config)
     space.startup() # Initialize all builtin modules
-    space.setitem(space.builtin.w_dict, space.wrap('AssertionError'),
-                  appsupport.build_pytest_assertion(space))
+    if config.objspace.std.reinterpretasserts:
+        space.setitem(space.builtin.w_dict, space.wrap('AssertionError'),
+                    appsupport.build_pytest_assertion(space))
     space.setitem(space.builtin.w_dict, space.wrap('raises'),
                   space.wrap(appsupport.app_raises))
     space.setitem(space.builtin.w_dict, space.wrap('skip'),
diff --git a/pypy/tool/pytest/test/apptest_xx.py b/pypy/tool/pytest/test/apptest_xx.py
deleted file mode 100644
--- a/pypy/tool/pytest/test/apptest_xx.py
+++ /dev/null
@@ -1,3 +0,0 @@
-def test_fail():
-    x = 'foo'
-    assert x == 'bar'
diff --git a/pypy/tool/pytest/test/test_appsupport.py b/pypy/tool/pytest/test/test_appsupport.py
--- a/pypy/tool/pytest/test/test_appsupport.py
+++ b/pypy/tool/pytest/test/test_appsupport.py
@@ -154,7 +154,7 @@
     result = testdir.runpytest(p)
     assert result.ret == 1
     result.stdout.fnmatch_lines([
-        "*E*application-level*KeyError*42*",
+        "*E*(application-level) AssertionError",
     ])
 
 def test_apptest_fail_rewrite(testdir):
@@ -167,7 +167,9 @@
     result = testdir.runpytest(p, "--applevel-rewrite")
     assert result.ret == 1
     result.stdout.fnmatch_lines([
-        "*E*application-level*KeyError*42*",
+        "*E*application-level*AssertionError: assert 'foo' == 'bar'",
+        "*E*- foo*",
+        "*E*+ bar*",
     ])
 
 


More information about the pypy-commit mailing list