comparison tests/run.py @ 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 4217a050a088
children
comparison
equal deleted inserted replaced
1457:019c3e194fba 1458:dcf9eff9b5b7
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import optparse 3 import optparse
4 import os 4 import os
5 import sys 5 import sys
6 6 import unittest
7 if sys.version_info[:2] < (2, 7):
8 import unittest2 as unittest
9 else:
10 import unittest
11 7
12 if __name__ == '__main__': 8 if __name__ == '__main__':
13 description = ("This script runs the hgsubversion tests. If no tests are " 9 description = ("This script runs the hgsubversion tests. If no tests are "
14 "specified, all known tests are implied.") 10 "specified, all known tests are implied.")
15 parser = optparse.OptionParser(usage="%prog [options] [TESTS ...]", 11 parser = optparse.OptionParser(usage="%prog [options] [TESTS ...]",
61 for arg in args] 57 for arg in args]
62 58
63 loader = unittest.TestLoader() 59 loader = unittest.TestLoader()
64 suite = unittest.TestSuite() 60 suite = unittest.TestSuite()
65 61
62 if sys.version_info[:2] < (2, 7):
63 import glob
64 def discover(start_dir, pattern='test*.py', top_level_dir=None):
65 tests = []
66 sys.path.append(start_dir)
67 for path in glob.glob(os.path.join(start_dir, pattern)):
68 name = os.path.splitext(os.path.basename(path))[0]
69 tests.append(loader.loadTestsFromModule(__import__(name)))
70 return tests
71 loader.discover = discover
72
66 if not args: 73 if not args:
67 suite = loader.discover('.') 74 suite.addTests(loader.discover('.'))
68 75
69 if options.comprehensive: 76 if options.comprehensive:
70 suite.addTests(loader.discover('comprehensive', 77 suite.addTests(loader.discover('comprehensive',
71 top_level_dir='comprehensive')) 78 top_level_dir='comprehensive'))
72 else: 79 else: