[pypy-dev] Running CPython unittests on PyPy

Seo Sanghyeon tinuviel at sparcs.kaist.ac.kr
Wed Jul 14 14:24:17 CEST 2004


Today I could run CPython unittests on top of PyPy.

test_call is passed. :-)

Some problems:

1) For some reason, test_support complains if not imported from
test package. Error message is:

ImportError: test_support must be imported from the test package

2) PyPy's sys.path includes appspace/ and interpreter/. And they
have their own test/ subdirectory, thus breaking import from test
package.

3) PyPy methods have no __doc__. CPython methods always have __doc__,
even if it is None. This confuses unittest:

try:
    self.__testMethodName = methodName
    testMethod = getattr(self, methodName)
    self.__testMethodDoc = testMethod.__doc__
except AttributeError:
    raise ValueError
    # ...

testMethod.__doc__ never raises AttributeError in CPython. So this
error is wrongly reported as missing test method, not test method
docstring.

I just wanted to run CPython unittests on PyPy, without fixing these
glitches. Here are workarounds:

1) mv appspace/test appspace/xtest
2) mv interpreter/test interpreter/xtest
3) cp /usr/lib/python2.3/unittest.py appspace
4) Patch unittest.py:

--- unittest.py.orig    2004-07-14 21:19:19.000000000 +0900
+++ unittest.py 2004-07-14 21:19:29.000000000 +0900
@@ -169,7 +169,7 @@
         try:
             self.__testMethodName = methodName
             testMethod = getattr(self, methodName)
-            self.__testMethodDoc = testMethod.__doc__
+            self.__testMethodDoc = None # testMethod.__doc__
         except AttributeError:
             raise ValueError, "no such test method in %s: %s" % \
                   (self.__class__, methodName)

5) Copy CPython Lib/test to work directory.
6) pypy test/test_call.py

You will see "Ran 27 tests in 22.790s".
CPython reports "Ran 27 tests in 0.008s".

That gives 3500x slow performance. Well, that was expected.

Happy hacking,



More information about the Pypy-dev mailing list