##// END OF EJS Templates
run-tests: initial support for running tests with unittest...
Gregory Szorc -
r21426:791bdd65 default
parent child Browse files
Show More
@@ -57,6 +57,7 b' import re'
57 import threading
57 import threading
58 import killdaemons as killmod
58 import killdaemons as killmod
59 import Queue as queue
59 import Queue as queue
60 import unittest
60
61
61 processlock = threading.Lock()
62 processlock = threading.Lock()
62
63
@@ -187,6 +188,9 b' def getparser():'
187 parser.add_option("--tmpdir", type="string",
188 parser.add_option("--tmpdir", type="string",
188 help="run tests in the given temporary directory"
189 help="run tests in the given temporary directory"
189 " (implies --keep-tmpdir)")
190 " (implies --keep-tmpdir)")
191 parser.add_option("--unittest", action="store_true",
192 help="run tests with Python's unittest package"
193 " (this is an experimental feature)")
190 parser.add_option("-v", "--verbose", action="store_true",
194 parser.add_option("-v", "--verbose", action="store_true",
191 help="output verbose messages")
195 help="output verbose messages")
192 parser.add_option("--view", type="string",
196 parser.add_option("--view", type="string",
@@ -255,6 +259,13 b' def parseargs(args, parser):'
255
259
256 if options.jobs < 1:
260 if options.jobs < 1:
257 parser.error('--jobs must be positive')
261 parser.error('--jobs must be positive')
262 if options.unittest:
263 if options.jobs > 1:
264 sys.stderr.write(
265 'warning: --jobs has no effect with --unittest')
266 if options.loop:
267 sys.stderr.write(
268 'warning: --loop has no effect with --unittest')
258 if options.interactive and options.debug:
269 if options.interactive and options.debug:
259 parser.error("-i/--interactive and -d/--debug are incompatible")
270 parser.error("-i/--interactive and -d/--debug are incompatible")
260 if options.debug:
271 if options.debug:
@@ -1172,6 +1183,17 b' class TestRunner(object):'
1172 print "running all tests"
1183 print "running all tests"
1173 tests = orig
1184 tests = orig
1174
1185
1186 if self.options.unittest:
1187 suite = unittest.TestSuite()
1188 for count, testpath in enumerate(tests):
1189 suite.addTest(self._gettest(testpath, count, asunit=True))
1190
1191 verbosity = 1
1192 if self.options.verbose:
1193 verbosity = 2
1194 runner = unittest.TextTestRunner(verbosity=verbosity)
1195 runner.run(suite)
1196 else:
1175 self._executetests(tests)
1197 self._executetests(tests)
1176
1198
1177 failed = len(self.results['!'])
1199 failed = len(self.results['!'])
@@ -1207,7 +1229,7 b' class TestRunner(object):'
1207 if warned:
1229 if warned:
1208 return 80
1230 return 80
1209
1231
1210 def _gettest(self, test, count):
1232 def _gettest(self, test, count, asunit=False):
1211 """Obtain a Test by looking at its filename.
1233 """Obtain a Test by looking at its filename.
1212
1234
1213 Returns a Test instance. The Test may not be runnable if it doesn't
1235 Returns a Test instance. The Test may not be runnable if it doesn't
@@ -1224,7 +1246,17 b' class TestRunner(object):'
1224 refpath = os.path.join(self.testdir, test + out)
1246 refpath = os.path.join(self.testdir, test + out)
1225 break
1247 break
1226
1248
1227 return testcls(self, test, count, refpath)
1249 t = testcls(self, test, count, refpath)
1250
1251 if not asunit:
1252 return t
1253
1254 # If we want a unittest compatible object, we wrap our Test.
1255 class MercurialTest(unittest.TestCase):
1256 def runTest(self):
1257 t.run()
1258
1259 return MercurialTest()
1228
1260
1229 def _cleanup(self):
1261 def _cleanup(self):
1230 """Clean up state from this test invocation."""
1262 """Clean up state from this test invocation."""
General Comments 0
You need to be logged in to leave comments. Login now