##// END OF EJS Templates
run-tests: add a way to list tests, with JSON and XUnit support...
Siddharth Agarwal -
r32704:1270b00a default
parent child Browse files
Show More
@@ -263,6 +263,8 b' def getparser():'
263 263 help="keep temporary directory after running tests")
264 264 parser.add_option("-k", "--keywords",
265 265 help="run tests matching keywords")
266 parser.add_option("--list-tests", action="store_true",
267 help="list tests instead of running them")
266 268 parser.add_option("-l", "--local", action="store_true",
267 269 help="shortcut for --with-hg=<testdir>/../hg, "
268 270 "and --with-chg=<testdir>/../contrib/chg/chg if --chg is set")
@@ -1907,6 +1909,25 b' class TextTestRunner(unittest.TextTestRu'
1907 1909
1908 1910 self._runner = runner
1909 1911
1912 def listtests(self, test):
1913 result = TestResult(self._runner.options, self.stream,
1914 self.descriptions, 0)
1915 test = sorted(test, key=lambda t: t.name)
1916 for t in test:
1917 print(t.name)
1918 result.addSuccess(t)
1919
1920 if self._runner.options.xunit:
1921 with open(self._runner.options.xunit, "wb") as xuf:
1922 self._writexunit(result, xuf)
1923
1924 if self._runner.options.json:
1925 jsonpath = os.path.join(self._runner._testdir, b'report.json')
1926 with open(jsonpath, 'w') as fp:
1927 self._writejson(result, fp)
1928
1929 return result
1930
1910 1931 def run(self, test):
1911 1932 result = TestResult(self._runner.options, self.stream,
1912 1933 self.descriptions, self.verbosity)
@@ -2384,16 +2405,19 b' class TestRunner(object):'
2384 2405 verbosity = 2
2385 2406 runner = TextTestRunner(self, verbosity=verbosity)
2386 2407
2387 if self._installdir:
2388 self._installhg()
2389 self._checkhglib("Testing")
2408 if self.options.list_tests:
2409 result = runner.listtests(suite)
2390 2410 else:
2391 self._usecorrectpython()
2392 if self.options.chg:
2393 assert self._installdir
2394 self._installchg()
2411 if self._installdir:
2412 self._installhg()
2413 self._checkhglib("Testing")
2414 else:
2415 self._usecorrectpython()
2416 if self.options.chg:
2417 assert self._installdir
2418 self._installchg()
2395 2419
2396 result = runner.run(suite)
2420 result = runner.run(suite)
2397 2421
2398 2422 if result.failures:
2399 2423 failed = True
@@ -224,6 +224,60 b' test --xunit support'
224 224 test-failure-unicode.t * (glob)
225 225 test-failure.t * (glob)
226 226 test-success.t * (glob)
227
228 $ rt --list-tests
229 test-failure-unicode.t
230 test-failure.t
231 test-success.t
232
233 $ rt --list-tests --json
234 test-failure-unicode.t
235 test-failure.t
236 test-success.t
237 $ cat report.json
238 testreport ={
239 "test-failure-unicode.t": {
240 "result": "success"
241 },
242 "test-failure.t": {
243 "result": "success"
244 },
245 "test-success.t": {
246 "result": "success"
247 }
248 } (no-eol)
249
250 $ rt --list-tests --xunit=xunit.xml
251 test-failure-unicode.t
252 test-failure.t
253 test-success.t
254 $ cat xunit.xml
255 <?xml version="1.0" encoding="utf-8"?>
256 <testsuite errors="0" failures="0" name="run-tests" skipped="0" tests="0">
257 <testcase name="test-failure-unicode.t"/>
258 <testcase name="test-failure.t"/>
259 <testcase name="test-success.t"/>
260 </testsuite>
261
262 $ rt --list-tests test-failure* --json --xunit=xunit.xml
263 test-failure-unicode.t
264 test-failure.t
265 $ cat report.json
266 testreport ={
267 "test-failure-unicode.t": {
268 "result": "success"
269 },
270 "test-failure.t": {
271 "result": "success"
272 }
273 } (no-eol)
274 $ cat xunit.xml
275 <?xml version="1.0" encoding="utf-8"?>
276 <testsuite errors="0" failures="0" name="run-tests" skipped="0" tests="0">
277 <testcase name="test-failure-unicode.t"/>
278 <testcase name="test-failure.t"/>
279 </testsuite>
280
227 281 $ rm test-failure-unicode.t
228 282
229 283 test for --retest
General Comments 0
You need to be logged in to leave comments. Login now