[pypy-svn] r38758 - in pypy/dist/pypy: objspace/cpy/test tool/pytest

hpk at codespeak.net hpk at codespeak.net
Tue Feb 13 21:31:12 CET 2007


Author: hpk
Date: Tue Feb 13 21:31:11 2007
New Revision: 38758

Added:
   pypy/dist/pypy/tool/pytest/modcheck.py   (contents, props changed)
Modified:
   pypy/dist/pypy/objspace/cpy/test/conftest.py
Log:
* skip cpy objspace tests if there is no ctypes
* add helper to skip/check for imports 



Modified: pypy/dist/pypy/objspace/cpy/test/conftest.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/test/conftest.py	(original)
+++ pypy/dist/pypy/objspace/cpy/test/conftest.py	Tue Feb 13 21:31:11 2007
@@ -1,13 +1,8 @@
 
 import py
-
-try:
-    import ctypes
-except ImportError:
-    ctypes = None
+from pypy.tool.pytest.modcheck import skipimporterror
 
 class Directory(py.test.collect.Directory):
     def run(self):
-        if ctypes is None:
-            py.test.skip("no ctypes module available")
+        skipimporterror("ctypes")
         return super(Directory, self).run()

Added: pypy/dist/pypy/tool/pytest/modcheck.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/pytest/modcheck.py	Tue Feb 13 21:31:11 2007
@@ -0,0 +1,14 @@
+import py
+
+def skipimporterror(name):
+    if not hasimport(name):
+        __tracebackhide__ = True
+        py.test.skip("cannot import %r module" % (name,))
+
+def hasimport(name):
+    try:
+        __import__(name)
+    except ImportError:
+        return False
+    else:
+        return True



More information about the Pypy-commit mailing list