Py2/3 portability fixes in test runner
authorStefan Behnel <scoder@users.berlios.de>
Thu, 14 Jan 2010 07:03:17 +0000 (08:03 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 14 Jan 2010 07:03:17 +0000 (08:03 +0100)
runtests.py

index 12a5f0b4c1a3038f0b0acb90a6d8f8e017acaeb2..18ead284d243eaa4e638626316418b89c8e72219 100644 (file)
@@ -408,26 +408,27 @@ class CythonRunTestCase(CythonCompileTestCase):
         if not child_id:
             result_code = 0
             try:
-                output = os.fdopen(result_handle, 'wb')
-                tests = None
                 try:
-                    partial_result = PartialTestResult(result)
-                    tests = doctest.DocTestSuite(module_name)
-                    tests.run(partial_result)
-                    gc.collect()
-                except Exception:
-                    if tests is None:
-                        # importing failed, try to fake a test class
-                        tests = _FakeClass(
-                            failureException=None,
-                            shortDescription = self.shortDescription,
-                            **{module_name: None})
-                    partial_result.addError(tests, sys.exc_info())
-                    result_code = 1
-                pickle.dump(partial_result.data(), output)
-            except:
-                import traceback
-                traceback.print_exc()
+                    output = os.fdopen(result_handle, 'wb')
+                    tests = None
+                    try:
+                        partial_result = PartialTestResult(result)
+                        tests = doctest.DocTestSuite(module_name)
+                        tests.run(partial_result)
+                        gc.collect()
+                    except Exception:
+                        if tests is None:
+                            # importing failed, try to fake a test class
+                            tests = _FakeClass(
+                                failureException=None,
+                                shortDescription = self.shortDescription,
+                                **{module_name: None})
+                        partial_result.addError(tests, sys.exc_info())
+                        result_code = 1
+                    pickle.dump(partial_result.data(), output)
+                except:
+                    import traceback
+                    traceback.print_exc()
             finally:
                 try: output.close()
                 except: pass
@@ -741,8 +742,13 @@ if __name__ == '__main__':
                              ''')
             sys.path.insert(0, cy3_dir)
     elif sys.version_info[0] >= 3:
-        # make sure we do not import (or run) Cython itself
-        options.with_cython = False
+        # make sure we do not import (or run) Cython itself (unless
+        # 2to3 was already run)
+        cy3_dir = os.path.join(WORKDIR, 'Cy3')
+        if os.path.isdir(cy3_dir):
+            sys.path.insert(0, cy3_dir)
+        else:
+            options.with_cython = False
         options.doctests    = False
         options.unittests   = False
         options.pyregr      = False