Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ This script will parse the results file produced by MSTest. | 6 """ This script will parse the results file produced by MSTest. |
| 7 | 7 |
| 8 The script takes a single argument containing the path to the Results.trx | 8 The script takes a single argument containing the path to the Results.trx |
| 9 file to parse. It will log relevant test run information, and exit with code 0 | 9 file to parse. It will log relevant test run information, and exit with code 0 |
| 10 if all tests passed, or code 1 if some test failed. | 10 if all tests passed, or code 1 if some test failed. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 # Parse the xml results file | 25 # Parse the xml results file |
| 26 tree = xml.etree.ElementTree.parse(sys.argv[1]) | 26 tree = xml.etree.ElementTree.parse(sys.argv[1]) |
| 27 root = tree.getroot() | 27 root = tree.getroot() |
| 28 results_node = root.find('{%s}Results' % MSTEST_NAMESPACE) | 28 results_node = root.find('{%s}Results' % MSTEST_NAMESPACE) |
| 29 results = results_node.findall('{%s}UnitTestResult' % MSTEST_NAMESPACE) | 29 results = results_node.findall('{%s}UnitTestResult' % MSTEST_NAMESPACE) |
| 30 test_run_name = root.attrib['name'] | 30 test_run_name = root.attrib['name'] |
| 31 | 31 |
| 32 exit_code = 0 | 32 exit_code = 0 |
| 33 | 33 |
| 34 # Print the results, note any failures by setting exit_code to 1 | 34 # Print the results, note any failures by setting exit_code to 1 |
| 35 print test_run_name | 35 #print test_run_name |
|
binji
2012/10/31 19:15:00
remove commented code
| |
| 36 for result in results: | 36 for result in results: |
| 37 fail_message = 'None.' | 37 fail_message = None |
| 38 if 'outcome' not in result.attrib: | 38 if 'outcome' not in result.attrib: |
| 39 result.attrib['outcome'] = 'Error' | 39 result.attrib['outcome'] = 'Error' |
| 40 | 40 |
| 41 if result.attrib['outcome'] != 'Passed': | 41 if result.attrib['outcome'] not in ('Passed', 'Inconclusive'): |
| 42 exit_code = 1 | 42 exit_code = 1 |
| 43 fail_element = result.find('{%s}Output/{%s}ErrorInfo/{%s}Message' % ( | 43 fail_element = result.find('{%s}Output/{%s}ErrorInfo/{%s}Message' % ( |
| 44 MSTEST_NAMESPACE, MSTEST_NAMESPACE, MSTEST_NAMESPACE)) | 44 MSTEST_NAMESPACE, MSTEST_NAMESPACE, MSTEST_NAMESPACE)) |
| 45 if fail_element is not None: | 45 if fail_element is not None: |
| 46 fail_message = fail_element.text | 46 fail_message = fail_element.text |
| 47 | 47 |
| 48 print 'Test: %s, Duration: %s, Outcome: %s, Reason: %s\n' % ( | 48 print 'TEST: %-35s [%s] [%s]' % (result.attrib['testName'], |
| 49 result.attrib['testName'], result.attrib.get('duration'), | 49 result.attrib.get('outcome'), result.attrib['duration']) |
| 50 result.attrib['outcome'], fail_message) | 50 if fail_message: |
| 51 print 'Reason: %s' % fail_message | |
| 52 elif exit_code: | |
| 53 print 'No error message given' | |
| 51 | 54 |
| 52 return exit_code | 55 return exit_code |
| 53 | 56 |
| 54 if __name__ == '__main__': | 57 if __name__ == '__main__': |
| 55 sys.exit(main()) | 58 sys.exit(main()) |
| OLD | NEW |