[pypy-commit] pypy py3k: support docstring-tests also in functions

antocuni noreply at buildbot.pypy.org
Wed Jan 25 17:12:20 CET 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r51762:d3e2c1dbfd08
Date: 2012-01-25 16:46 +0100
http://bitbucket.org/pypy/pypy/changeset/d3e2c1dbfd08/

Log:	support docstring-tests also in functions

diff --git a/pypy/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -428,7 +428,8 @@
             return target()
         space = gettestobjspace()
         filename = self._getdynfilename(target)
-        func = app2interp_temp(target, filename=filename)
+        src = extract_docstring_if_empty_function(target)
+        func = app2interp_temp(src, filename=filename)
         print "executing", func
         self.execute_appex(space, func, space)
 
@@ -482,9 +483,11 @@
     def empty_func():
         ""
         pass
-    co_code = fn.func_code.co_code
-    if co_code == empty_func.func_code.co_code and fn.__doc__ is not None:
-        head = '%s(self):' % fn.func_name
+    empty_func_code = empty_func.func_code
+    fn_code = fn.func_code
+    if fn_code.co_code == empty_func_code.co_code and fn.__doc__ is not None:
+        fnargs = py.std.inspect.getargs(fn_code).args
+        head = '%s(%s):' % (fn.func_name, ', '.join(fnargs))
         body = py.code.Source(fn.__doc__)
         return head + str(body.indent())
     else:
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
@@ -5,6 +5,11 @@
 def app_test_something(): 
     assert 42 == 42 
 
+def app_test_code_in_docstring_failing():
+    """
+    assert False
+    """
+
 class AppTestSomething: 
     def test_method_app(self): 
         assert 23 == 23
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
@@ -42,10 +42,20 @@
         assert "test_method_app" in passed[1].nodeid
         
     def test_docstring_in_methods(self, testdir): 
-        sorter = testdir.inline_run("-k", "test_code_in_docstring", innertest)
+        sorter = testdir.inline_run("-k", "AppTestSomething test_code_in_docstring",
+                                    innertest)
         passed, skipped, failed = sorter.listoutcomes()
         assert len(passed) == 1
         assert len(failed) == 1
         assert skipped == []
         assert "test_code_in_docstring_ignored" in passed[0].nodeid
         assert "test_code_in_docstring_failing" in failed[0].nodeid
+
+    def test_docstring_in_functions(self, testdir): 
+        sorter = testdir.inline_run("-k", "app_test_code_in_docstring", innertest)
+        passed, skipped, failed = sorter.listoutcomes()
+        assert passed == []
+        assert len(failed) == 1
+        assert skipped == []
+        assert "app_test_code_in_docstring_failing" in failed[0].nodeid
+


More information about the pypy-commit mailing list