[pypy-commit] pypy py3tests: hg merge apptest-file
rlamy
pypy.commits at gmail.com
Sun Apr 15 13:01:50 EDT 2018
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3tests
Changeset: r94343:77838bcabf15
Date: 2018-04-15 18:01 +0100
http://bitbucket.org/pypy/pypy/changeset/77838bcabf15/
Log: hg merge apptest-file
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -252,6 +252,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/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -132,10 +132,9 @@
"""
def accept_regular_test(self):
if self.config.option.runappdirect:
- # only collect regular tests if we are in an 'app_test' directory,
- # or in test_lib_pypy
+ # only collect regular tests if we are in test_lib_pypy
for name in self.listnames():
- if "app_test" in name or "test_lib_pypy" in name:
+ if "test_lib_pypy" in name:
return True
return False
return True
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
@@ -237,7 +237,7 @@
src = extract_docstring_if_empty_function(target)
if self.config.option.runappdirect:
return run_with_python(self.config.option.python, src, None)
- space = gettestobjspace()
+ space = gettestobjspace(**{'objspace.std.reinterpretasserts': True})
filename = self._getdynfilename(target)
func = app2interp_temp(src, 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,7 +7,7 @@
_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)
@@ -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/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
@@ -24,10 +24,16 @@
def test_method(self):
pass
""")
+ testdir.makepyfile(apptest_collection="""
+ def test_app():
+ pass
+ """)
setpypyconftest(testdir)
result = testdir.runpytest("--collectonly")
assert result.ret == 0
result.stdout.fnmatch_lines([
+ "*AppTestModule*apptest_collection*",
+ "*AppTestFunction*test_app*",
"*Function*test_func*",
"*Class*TestClassInt*",
"*Function*test_method*",
@@ -128,6 +134,47 @@
"*E*application-level*KeyError*42*",
])
+def test_apptest_raise(testdir):
+ setpypyconftest(testdir)
+ p = testdir.makepyfile(apptest_raise="""
+ def test_raise():
+ raise KeyError(42)
+ """)
+ result = testdir.runpytest(p)
+ assert result.ret == 1
+ result.stdout.fnmatch_lines([
+ "*E*application-level*KeyError*42*",
+ ])
+
+def test_apptest_fail_plain(testdir):
+ setpypyconftest(testdir)
+ p = testdir.makepyfile(apptest_fail="""
+ def test_fail():
+ x = 'foo'
+ assert x == 'bar'
+ """)
+ result = testdir.runpytest(p)
+ assert result.ret == 1
+ result.stdout.fnmatch_lines([
+ "*E*(application-level) AssertionError",
+ ])
+
+def test_apptest_fail_rewrite(testdir):
+ setpypyconftest(testdir)
+ p = testdir.makepyfile(apptest_fail_rewrite="""
+ def test_fail():
+ x = 'foo'
+ assert x == 'bar'
+ """)
+ result = testdir.runpytest(p, "--applevel-rewrite")
+ assert result.ret == 1
+ result.stdout.fnmatch_lines([
+ "*E*application-level*AssertionError: assert 'foo' == 'bar'",
+ "*E*- foo*",
+ "*E*+ bar*",
+ ])
+
+
def app_test_raises():
info = raises(TypeError, id)
assert info.type is TypeError
More information about the pypy-commit
mailing list