comparison tests/run-tests.py @ 21532:9d2ba7e2324d

run-tests: move loop to a named argument of TestSuite.__init__
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 25 Apr 2014 15:08:03 -0700
parents 7fcda22acc43
children aecac8059c00
comparison
equal deleted inserted replaced
21531:7fcda22acc43 21532:9d2ba7e2324d
1152 1152
1153 class TestSuite(unittest.TestSuite): 1153 class TestSuite(unittest.TestSuite):
1154 """Custom unitest TestSuite that knows how to execute Mercurial tests.""" 1154 """Custom unitest TestSuite that knows how to execute Mercurial tests."""
1155 1155
1156 def __init__(self, runner, jobs=1, whitelist=None, blacklist=None, 1156 def __init__(self, runner, jobs=1, whitelist=None, blacklist=None,
1157 retest=False, keywords=None, 1157 retest=False, keywords=None, loop=False,
1158 *args, **kwargs): 1158 *args, **kwargs):
1159 """Create a new instance that can run tests with a configuration. 1159 """Create a new instance that can run tests with a configuration.
1160 1160
1161 jobs specifies the number of jobs to run concurrently. Each test 1161 jobs specifies the number of jobs to run concurrently. Each test
1162 executes on its own thread. Tests actually spawn new processes, so 1162 executes on its own thread. Tests actually spawn new processes, so
1172 retest denotes whether to retest failed tests. This arguably belongs 1172 retest denotes whether to retest failed tests. This arguably belongs
1173 outside of TestSuite. 1173 outside of TestSuite.
1174 1174
1175 keywords denotes key words that will be used to filter which tests 1175 keywords denotes key words that will be used to filter which tests
1176 to execute. This arguably belongs outside of TestSuite. 1176 to execute. This arguably belongs outside of TestSuite.
1177
1178 loop denotes whether to loop over tests forever.
1177 """ 1179 """
1178 super(TestSuite, self).__init__(*args, **kwargs) 1180 super(TestSuite, self).__init__(*args, **kwargs)
1179 1181
1180 self._runner = runner 1182 self._runner = runner
1181 self._jobs = jobs 1183 self._jobs = jobs
1182 self._whitelist = whitelist 1184 self._whitelist = whitelist
1183 self._blacklist = blacklist 1185 self._blacklist = blacklist
1184 self._retest = retest 1186 self._retest = retest
1185 self._keywords = keywords 1187 self._keywords = keywords
1188 self._loop = loop
1186 1189
1187 def run(self, result): 1190 def run(self, result):
1188 # We have a number of filters that need to be applied. We do this 1191 # We have a number of filters that need to be applied. We do this
1189 # here instead of inside Test because it makes the running logic for 1192 # here instead of inside Test because it makes the running logic for
1190 # Test simpler. 1193 # Test simpler.
1243 except queue.Empty: 1246 except queue.Empty:
1244 continue 1247 continue
1245 running -= 1 1248 running -= 1
1246 if tests and not running == self._jobs: 1249 if tests and not running == self._jobs:
1247 test = tests.pop(0) 1250 test = tests.pop(0)
1248 if self._runner.options.loop: 1251 if self._loop:
1249 tests.append(test) 1252 tests.append(test)
1250 t = threading.Thread(target=job, name=test.name, 1253 t = threading.Thread(target=job, name=test.name,
1251 args=(test, result)) 1254 args=(test, result))
1252 t.start() 1255 t.start()
1253 running += 1 1256 running += 1
1509 suite = TestSuite(self, jobs=self.options.jobs, 1512 suite = TestSuite(self, jobs=self.options.jobs,
1510 whitelist=self.options.whitelisted, 1513 whitelist=self.options.whitelisted,
1511 blacklist=self.options.blacklist, 1514 blacklist=self.options.blacklist,
1512 retest=self.options.retest, 1515 retest=self.options.retest,
1513 keywords=self.options.keywords, 1516 keywords=self.options.keywords,
1517 loop=self.options.loop,
1514 tests=tests) 1518 tests=tests)
1515 verbosity = 1 1519 verbosity = 1
1516 if self.options.verbose: 1520 if self.options.verbose:
1517 verbosity = 2 1521 verbosity = 2
1518 runner = TextTestRunner(self, verbosity=verbosity) 1522 runner = TextTestRunner(self, verbosity=verbosity)