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 root = tree.getroot() | 25 root = tree.getroot() |
26 results_node = root.find('{%s}Results' % MSTEST_NAMESPACE) | 26 results_node = root.find('{%s}Results' % MSTEST_NAMESPACE) |
27 results = results_node.findall('{%s}UnitTestResult' % MSTEST_NAMESPACE) | 27 results = results_node.findall('{%s}UnitTestResult' % MSTEST_NAMESPACE) |
28 test_run_name = root.attrib['name'] | 28 test_run_name = root.attrib['name'] |
29 | 29 |
30 exit_code = 0 | 30 exit_code = 0 |
31 | 31 |
32 # Print the results, note any failures by setting exit_code to 1 | 32 # Print the results, note any failures by setting exit_code to 1 |
33 print test_run_name | 33 print test_run_name |
34 for result in results: | 34 for result in results: |
| 35 fail_message = 'None.' |
35 if result.attrib['outcome'] != 'Passed': | 36 if result.attrib['outcome'] != 'Passed': |
36 exit_code = 1 | 37 exit_code = 1 |
37 print 'Test: %s, Duration: %s, Outcome: %s\n' % ( | 38 fail_element = result.find('{%s}Output/{%s}ErrorInfo/{%s}Message' % ( |
38 result.attrib['testName'], result.attrib['duration'], | 39 MSTEST_NAMESPACE, MSTEST_NAMESPACE, MSTEST_NAMESPACE)) |
39 result.attrib['outcome']) | 40 if fail_element is not None: |
| 41 fail_message = fail_element.text |
| 42 print 'Test: %s, Duration: %s, Outcome: %s, Reason: %s\n' % ( |
| 43 result.attrib['testName'], result.attrib['duration'], |
| 44 result.attrib['outcome'], fail_message) |
40 | 45 |
41 return exit_code | 46 return exit_code |
42 | 47 |
43 if __name__ == '__main__': | 48 if __name__ == '__main__': |
44 sys.exit(main()) | 49 sys.exit(main()) |
OLD | NEW |