diff options
author | Antonio Cuni <anto.cuni@gmail.com> | 2020-03-25 17:55:23 +0100 |
---|---|---|
committer | Antonio Cuni <anto.cuni@gmail.com> | 2020-03-25 17:55:23 +0100 |
commit | 516937147fd74b2a3ef01bd858b940ada378196b (patch) | |
tree | 771ac25c0d12a20324c6b96b5dd1cc2e5d02cc64 /pypy/tool | |
parent | fix these two tests which were failing after the change of the repr (diff) | |
download | pypy-516937147fd74b2a3ef01bd858b940ada378196b.tar.gz pypy-516937147fd74b2a3ef01bd858b940ada378196b.tar.bz2 pypy-516937147fd74b2a3ef01bd858b940ada378196b.zip |
Be more robust when defining w_* methods in applevel tests:
- the old logic didn't work in case the function was defined at module level
(i.e., when the function body was indented by 4 spaces)
- the old logic assumed that the w_ method has the same name as its actual
function
(grafted from 7bab68baace2f97e1fcea7abd966aaccae10dbd3)
Diffstat (limited to 'pypy/tool')
-rw-r--r-- | pypy/tool/pytest/apptest.py | 7 | ||||
-rw-r--r-- | pypy/tool/pytest/test/test_pytestsupport.py | 8 |
2 files changed, 11 insertions, 4 deletions
diff --git a/pypy/tool/pytest/apptest.py b/pypy/tool/pytest/apptest.py index 2e4e8a8f36..b5906ede34 100644 --- a/pypy/tool/pytest/apptest.py +++ b/pypy/tool/pytest/apptest.py @@ -68,12 +68,12 @@ class AppTestMethod(py.test.collect.Function): else: obj = getattr(instance, name) if isinstance(obj, types.MethodType): - source = py.std.inspect.getsource(obj).lstrip() + source = py.code.Source(obj).indent() w_func = space.appexec([], textwrap.dedent(""" (): - %s + %s return %s - """) % (source, name)) + """) % (source, obj.__name__)) w_obj = Method(space, w_func, w_instance, space.w_None) else: w_obj = obj @@ -131,4 +131,3 @@ class AppClassCollector(py.test.Class): space.newtuple([]), space.newdict()) self.w_class = w_class - diff --git a/pypy/tool/pytest/test/test_pytestsupport.py b/pypy/tool/pytest/test/test_pytestsupport.py index 9255054997..e72b83145f 100644 --- a/pypy/tool/pytest/test/test_pytestsupport.py +++ b/pypy/tool/pytest/test/test_pytestsupport.py @@ -58,6 +58,9 @@ def test_appexecinfo(space): pass assert not appex.errisinstance(A) +# this is used by test_wrapped_function_with_different_name below +def inc(self, x): + return x+1 class AppTestWithWrappedInterplevelAttributes: def setup_class(cls): @@ -80,6 +83,11 @@ class AppTestWithWrappedInterplevelAttributes: def test_equal(self): assert self.compute(3) == 5 + w_inc = inc + + def test_wrapped_function_with_different_name(self): + assert self.inc(41) == 42 + def test_app_test_blow(testdir): conftestpath.copy(testdir.tmpdir) |