Skip to content

Instantly share code, notes, and snippets.

@007bsd
Created December 22, 2017 08:20
Show Gist options
  • Select an option

  • Save 007bsd/8eb74ee176b31747ccea3be2040e4c8c to your computer and use it in GitHub Desktop.

Select an option

Save 007bsd/8eb74ee176b31747ccea3be2040e4c8c to your computer and use it in GitHub Desktop.
parsing robot xml
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