[py-svn] py-trunk commit cd8564b53dee: fix test_importall to not stop on skipped plugins and fix the uncovered failure of genscript: standalone.py template is now safely importable

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Jan 15 18:45:27 CET 2010


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1263577506 -3600
# Node ID cd8564b53dee0a6eada8e73f9cd404d05c6c102b
# Parent 1464edd0ddb6477d14537505db642e80e1ceb1a2
fix test_importall to not stop on skipped plugins and fix the uncovered failure of genscript: standalone.py template is now safely importable

--- a/py/_plugin/standalonetemplate.py
+++ b/py/_plugin/standalonetemplate.py
@@ -8,18 +8,10 @@ import base64
 import zlib
 import imp
 
-if sys.version_info >= (3,0):
-    exec("def do_exec(co, loc): exec(co, loc)\n")
-    import pickle
-    sources = sources.encode("ascii") # ensure bytes 
-    sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)))
-else:
-    import cPickle as pickle
-    exec("def do_exec(co, loc): exec co in loc\n")
-    sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
+class DictImporter(object):
+    def __init__(self, sources):
+        self.sources = sources
 
-class DictImporter(object):
-    sources = sources
     def find_module(self, fullname, path=None):
         if fullname in self.sources:
             return self
@@ -53,12 +45,19 @@ class DictImporter(object):
             res = self.sources.get(name+'.__init__')
         return res
 
+if __name__ == "__main__":
+    if sys.version_info >= (3,0):
+        exec("def do_exec(co, loc): exec(co, loc)\n")
+        import pickle
+        sources = sources.encode("ascii") # ensure bytes 
+        sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)))
+    else:
+        import cPickle as pickle
+        exec("def do_exec(co, loc): exec co in loc\n")
+        sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
 
+    importer = DictImporter(sources)
+    sys.meta_path.append(importer)
 
-importer = DictImporter()
-
-sys.meta_path.append(importer)
-
-if __name__ == "__main__":
     import py
     py.cmdline.pytest()

--- a/testing/root/test_py_imports.py
+++ b/testing/root/test_py_imports.py
@@ -1,6 +1,7 @@
 import py
 import types
 import sys
+from py._test.outcome import Skipped
 
 def checksubpackage(name):
     obj = getattr(py, name)
@@ -29,7 +30,6 @@ def test_importall():
     nodirs = [
         base.join('_path', 'gateway',),
         base.join('_code', 'oldmagic.py'),
-        base.join('_compat', 'testing'),
     ]
     if sys.version_info >= (3,0):
         nodirs.append(base.join('_code', '_assertionold.py'))
@@ -50,7 +50,10 @@ def test_importall():
             else:
                 relpath = relpath.replace(base.sep, '.')
                 modpath = 'py.%s' % relpath
-                check_import(modpath)
+                try:
+                    check_import(modpath)
+                except Skipped:
+                    pass
 
 def check_import(modpath):
     py.builtin.print_("checking import", modpath)



More information about the pytest-commit mailing list