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 11 matching lines...) Expand all Loading... | |
22 | 22 |
23 print "Processing results: %s" % sys.argv[1] | 23 print "Processing results: %s" % sys.argv[1] |
24 | 24 |
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 | |
33 | |
34 # 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 |
35 for result in results: | 33 for result in results: |
34 exit_code = 0 | |
36 fail_message = None | 35 fail_message = None |
37 if 'outcome' not in result.attrib: | 36 if 'outcome' not in result.attrib: |
38 result.attrib['outcome'] = 'Error' | 37 result.attrib['outcome'] = 'Error' |
39 | 38 |
40 if result.attrib['outcome'] not in ('Passed', 'Inconclusive'): | 39 if result.attrib['outcome'] not in ('Passed', 'Inconclusive'): |
41 exit_code = 1 | 40 exit_code = 1 |
42 fail_element = result.find('{%s}Output/{%s}ErrorInfo/{%s}Message' % ( | 41 fail_element = result.find('{%s}Output/{%s}ErrorInfo/{%s}Message' % ( |
43 MSTEST_NAMESPACE, MSTEST_NAMESPACE, MSTEST_NAMESPACE)) | 42 MSTEST_NAMESPACE, MSTEST_NAMESPACE, MSTEST_NAMESPACE)) |
44 if fail_element is not None: | 43 if fail_element is not None: |
45 fail_message = fail_element.text | 44 fail_message = fail_element.text |
46 | 45 |
47 print 'TEST: %-35s [%s] [%s]' % (result.attrib['testName'], | 46 print 'TEST: %-35s [%s] [%s]' % (result.attrib['testName'], |
48 result.attrib.get('outcome'), result.attrib['duration']) | 47 result.attrib.get('outcome'), result.attrib['duration']) |
49 if fail_message: | 48 if fail_message: |
50 print 'Reason: %s' % fail_message | 49 print 'Reason: %s' % fail_message |
51 elif exit_code: | 50 elif exit_code: |
binji
2012/11/08 19:13:06
exit_code is performing two functions: here it is
| |
52 print 'No error message given' | 51 print 'No error message given' |
53 | 52 |
54 return exit_code | 53 return exit_code |
binji
2012/11/08 19:13:06
here it is used to determine if any test failed.
| |
55 | 54 |
56 if __name__ == '__main__': | 55 if __name__ == '__main__': |
57 sys.exit(main()) | 56 sys.exit(main()) |
OLD | NEW |