Created
December 22, 2017 08:20
-
-
Save 007bsd/8eb74ee176b31747ccea3be2040e4c8c to your computer and use it in GitHub Desktop.
parsing robot xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from robot.api import ExecutionResult, ResultVisitor | |
| def _parse_results_xml(path): | |
| class ExecutionChecker(ResultVisitor): | |
| def __init__(self): | |
| self.results = { | |
| 'pass': 0, | |
| 'fail': 0, | |
| 'elapsed_time': 0 | |
| } | |
| def visit_test(self, test): | |
| if test.status == 'PASS': | |
| self.results['pass'] += 1 | |
| else: | |
| self.results['fail'] += 1 | |
| self.results['elapsed_time'] += test.elapsedtime | |
| def check_tests(inpath): | |
| result = ExecutionResult(inpath) | |
| ec = ExecutionChecker() | |
| result.visit(ec) | |
| s = ec.results['elapsed_time'] / 1000 | |
| m, s = divmod(s, 60) | |
| h, m = divmod(m, 60) | |
| time_string = '' | |
| if h: | |
| time_string = '{}h {}m {}s'.format(int(h), int(m), int(s)) | |
| else: | |
| time_string = '{}m {}s'.format(int(m), int(s)) | |
| ec.results['elapsed_time_str'] = time_string | |
| return ec.results | |
| return check_tests(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment