244 "tests": self.__testsRun, |
244 "tests": self.__testsRun, |
245 } |
245 } |
246 ) |
246 ) |
247 |
247 |
248 |
248 |
249 def _assembleTestCasesList(suite): |
249 def _assembleTestCasesList(suite, start): |
250 """ |
250 """ |
251 Protected function to assemble a list of test cases included in a test |
251 Protected function to assemble a list of test cases included in a test |
252 suite. |
252 suite. |
253 |
253 |
254 @param suite test suite to be inspected |
254 @param suite test suite to be inspected |
255 @type unittest.TestSuite |
255 @type unittest.TestSuite |
256 @return list of tuples containing the test case ID, the string |
256 @param start name of directory discovery was started at |
257 representation and the short description |
257 @type str |
258 @rtype list of tuples of (str, str, str) |
258 @return list of tuples containing the test case ID, the string representation, |
|
259 a short description and the path of the test file name |
|
260 @rtype list of tuples of (str, str, str, str) |
259 """ |
261 """ |
260 testCases = [] |
262 testCases = [] |
261 for test in suite: |
263 for test in suite: |
262 if isinstance(test, unittest.TestSuite): |
264 if isinstance(test, unittest.TestSuite): |
263 testCases.extend(_assembleTestCasesList(test)) |
265 testCases.extend(_assembleTestCasesList(test, start)) |
264 else: |
266 else: |
265 testId = test.id() |
267 testId = test.id() |
266 if ( |
268 if ( |
267 "ModuleImportFailure" not in testId |
269 "ModuleImportFailure" not in testId |
268 and "LoadTestsFailure" not in testId |
270 and "LoadTestsFailure" not in testId |
269 and "_FailedTest" not in testId |
271 and "_FailedTest" not in testId |
270 ): |
272 ): |
271 testCases.append((testId, str(test), test.shortDescription())) |
273 filename = os.path.join( |
|
274 start, test.__module__.replace(".", os.sep) + ".py" |
|
275 ) |
|
276 testCases.append((testId, str(test), test.shortDescription(), filename)) |
272 return testCases |
277 return testCases |
273 |
278 |
274 |
279 |
275 def runtest(argv): |
280 def runtest(argv, discoverOnly=False): |
276 """ |
281 """ |
277 Function to run the tests. |
282 Function to run and/or discover the tests. |
278 |
283 |
279 @param argv list of command line parameters. |
284 @param argv list of command line parameters. |
280 @type list of str |
285 @type list of str |
|
286 @param discoverOnly flag indicating to just discover the available test cases |
|
287 (defaults to False) |
|
288 @type bool (optional) |
281 """ |
289 """ |
282 from eric7.EricNetwork.EricJsonStreamWriter import EricJsonWriter |
290 from eric7.EricNetwork.EricJsonStreamWriter import EricJsonWriter |
283 |
291 |
284 writer = EricJsonWriter(argv[0], int(argv[1])) |
292 writer = EricJsonWriter(argv[0], int(argv[1])) |
285 del argv[:2] |
293 del argv[:2] |
409 sys.exit(1) |
416 sys.exit(1) |
410 |
417 |
411 collectedTests = { |
418 collectedTests = { |
412 "event": "collected", |
419 "event": "collected", |
413 "tests": [ |
420 "tests": [ |
414 {"id": id, "name": name, "description": desc} |
421 {"id": id, "name": name, "description": desc, "filename": filename} |
415 for id, name, desc in _assembleTestCasesList(test) |
422 for id, name, desc, filename in _assembleTestCasesList(test, discoveryStart) |
416 ], |
423 ], |
417 } |
424 } |
418 writer.write(collectedTests) |
425 writer.write(collectedTests) |
419 |
426 |
420 testResult = EricTestResult(writer, failfast) |
427 if not discoverOnly: |
421 startTestRun = getattr(testResult, "startTestRun", None) |
428 testResult = EricTestResult(writer, failfast) |
422 if startTestRun is not None: |
429 startTestRun = getattr(testResult, "startTestRun", None) |
423 startTestRun() |
430 if startTestRun is not None: |
424 try: |
431 startTestRun() |
425 test.run(testResult) |
432 try: |
426 finally: |
433 test.run(testResult) |
427 if cover: |
434 finally: |
428 cover.stop() |
435 if cover: |
429 cover.save() |
436 cover.stop() |
430 writer.write( |
437 cover.save() |
431 { |
438 writer.write( |
432 "event": "coverage", |
439 { |
433 "file": covDataFile, |
440 "event": "coverage", |
434 } |
441 "file": covDataFile, |
435 ) |
442 } |
436 stopTestRun = getattr(testResult, "stopTestRun", None) |
443 ) |
437 if stopTestRun is not None: |
444 stopTestRun = getattr(testResult, "stopTestRun", None) |
438 stopTestRun() |
445 if stopTestRun is not None: |
|
446 stopTestRun() |
439 |
447 |
440 writer.close() |
448 writer.close() |
441 sys.exit(0) |
449 sys.exit(0) |
442 |
450 |
443 |
451 |