changeset 1458:dcf9eff9b5b7

tests: drop unittest2 Mixed using unittest2.SkipTest and unittest.TestCase will cause skips result in errors. We are probably not going to rewriting every "unittest.TestCase" to "unittest2.TestCase", then unittest2 is causing more trouble with little benefit. Let's drop it. To remain support for Py 26 in run.py, a simple loader.discover is added.
author Jun Wu <quark@fb.com>
date Thu, 16 Jun 2016 04:54:51 +0100
parents 019c3e194fba
children b95fa72c74ae
files tests/run.py tests/test_util.py
diffstat 2 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run.py
+++ b/tests/run.py
@@ -3,11 +3,7 @@
 import optparse
 import os
 import sys
-
-if sys.version_info[:2] < (2, 7):
-    import unittest2 as unittest
-else:
-    import unittest
+import unittest
 
 if __name__ == '__main__':
     description = ("This script runs the hgsubversion tests. If no tests are "
@@ -63,8 +59,19 @@ if __name__ == '__main__':
     loader = unittest.TestLoader()
     suite = unittest.TestSuite()
 
+    if sys.version_info[:2] < (2, 7):
+        import glob
+        def discover(start_dir, pattern='test*.py', top_level_dir=None):
+            tests = []
+            sys.path.append(start_dir)
+            for path in glob.glob(os.path.join(start_dir, pattern)):
+                name = os.path.splitext(os.path.basename(path))[0]
+                tests.append(loader.loadTestsFromModule(__import__(name)))
+            return tests
+        loader.discover = discover
+
     if not args:
-        suite = loader.discover('.')
+        suite.addTests(loader.discover('.'))
 
         if options.comprehensive:
             suite.addTests(loader.discover('comprehensive',
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -39,13 +39,10 @@ except ImportError:
 try:
     SkipTest = unittest.SkipTest
 except AttributeError:
-    try:
-        from unittest2 import SkipTest
-    except ImportError:
-        try:
-            from nose import SkipTest
-        except ImportError:
-            SkipTest = None
+    if 'nose' in sys.modules:
+        SkipTest = sys.modules['nose'].SkipTest
+    else:
+        SkipTest = None
 
 from hgsubversion import svnwrap
 from hgsubversion import util