# Why meet the error "Incompatible child element 'statistics' for 'kw', when ExecutionResult for output.xml

I used the RF method to generate log/report html, sometimes I met the following issue:
from robot.api import ExecutionResult
log_result = ExecutionResult(os.path.join(self.filepath, ‘report\output.xml’))

Reading XML source ‘E:\Project\autoTestClourneySemi_20221008\dist\report\output.xml’ failed: Incompatible child element ‘statistics’ for ‘kw’.

I found the output.xml generated with wrong format like that:

<?xml version="1.0" encoding="UTF-8"?> 1sec Pauses the test executed for the given time. **** **** **All Tests** **** **** **case1** **suite1** **test01** **testFor** **testSum** **** **** **suites** **suites.TestSuite 2** **** **** Error in file 'F:\dist\suites\TestSuite_2.robot' on line 6: Library '..\..\execution\Local\common\sum.py' does not exist. Error in file 'F:\dist\suites\TestSuite_2.robot' on line 7: Variable file '..\..\execution\Lib\Variables.py' does not exist. Error in file 'F:\dist\suites\TestSuite_2.robot' on line 8: Resource file '..\resources\source1.robot' does not exist. Error in file 'F:\dist\suites\TestSuite_2.robot' on line 9: Resource file '..\resources\source2.txt' does not exist. str', 'sss'] ${list_1} 2 Verifies that the length of the given item is correct.${list_1}[0] 3 Verifies that the length of the given item is correct. ${d} 1 Returns the given values which can then be assigned to a variables.${d} = 1 case1 suite1 test Logs the given message with the given level. ${uname} zs Returns the given values which can then be assigned to a variables.${uname} = zs ${age} 33 Returns the given values which can then be assigned to a variables.${age} = 33 ${uname_type} type($uname) Evaluates the given expression in Python and returns the result. ${uname_type} = <class 'str'>${age_type} type($age) Evaluates the given expression in Python and returns the result.${age_type} = <class 'str'> ${age_to_int} int($age)+20 Evaluates the given expression in Python and returns the result. ${age_to_int} = 53${age_to_int_type} type($age_to_int) Evaluates the given expression in Python and returns the result.${age_to_int_type} = <class 'int'> ${ulist} zs ls ww Returns a list containing given items.${ulist} = ['zs', 'ls', 'ww'] ${ulist} Logs the given message with the given level. @{agelist} 19 20 33 Returns a list containing given items. @{agelist} = [ 19 | 20 | 33 ]${agelist} Logs the given message with the given level. Log @{agelist} Displays the given messages in the log file as keyword arguments. ${student} stu_name=zs stu_age=12 stu_class=chinese Creates and returns a dictionary based on the given items.${student} = {'stu_name': 'zs', 'stu_age': '12', 'stu_class': 'chinese'} ${student} Logs the given message with the given level. suite1 test01 for_ Logs the given message with the given level.${num} 1 2 3 1 ${num} Logs the given message with the given level. 2${num} Logs the given message with the given level. 3 ${num} Logs the given message with the given level. for_in_range Logs the given message with the given level.${target} 4 8 4 ${target} Logs the given message with the given level. 5${target} Logs the given message with the given level. 6 ${target} Logs the given message with the given level. 7${target} Logs the given message with the given level. suite1 testFor ${i} 1 5 1${i} ${j} 1${i}+1 1 ${result}${i}*${j} Evaluates the given expression in Python and returns the result.${result} = 1 ${i}*${j}=${result} Logs the given message with the given level.${j} Logs the given message with the given level. 2 ${i}${j} 1 ${i}+1 1${result} ${i}*${j} Evaluates the given expression in Python and returns the result. ${result} = 2${i}*${j}=${result} Logs the given message with the given level. ${j} Logs the given message with the given level. 2${result} ${i}*${j} Evaluates the given expression in Python and returns the result. ${result} = 4${i}*${j}=${result} Logs the given message with the given level. ${j} Logs the given message with the given level. 3${i} ${j} 1${i}+1 1 ${result}${i}*${j} Evaluates the given expression in Python and returns the result.${result} = 3 ${i}*${j}=${result} Logs the given message with the given level.${j} Logs the given message with the given level. 2 ${result}${i}*${j} Evaluates the given expression in Python and returns the result.${result} = 6 ${i}*${j}=${result} Logs the given message with the given level.${j} Logs the given message with the given level. 3 ${result}${i}*${j} Evaluates the given expression in Python and returns the result.${result} = 9 ${i}*${j}=${result} Logs the given message with the given level.${j} Logs the given message with the given level. 4 ${i}${j} 1 ${i}+1 1${result} ${i}*${j} Evaluates the given expression in Python and returns the result. ${result} = 4${i}*${j}=${result} Logs the given message with the given level. ${j} Logs the given message with the given level. 2${result} ${i}*${j} Evaluates the given expression in Python and returns the result. ${result} = 8${i}*${j}=${result} Logs the given message with the given level. ${j} Logs the given message with the given level. 3${result} ${i}*${j} Evaluates the given expression in Python and returns the result. ${result} = 12${i}*${j}=${result} Logs the given message with the given level. ${j} Logs the given message with the given level. 4${result} ${i}*${j} Evaluates the given expression in Python and returns the result. ${result} = 16${i}*${j}=${result} Logs the given message with the given level. ${j} Logs the given message with the given level. suite1 testFor${i} 1 5 1 ${j} 2 5 2${r} ${i}${j} No keyword with name 'Sum' found. \$r Logs the given message with the given level. suite1 testSum No keyword with name 'Sum' found. Test Suite1 1 All Tests case1 suite1 test01 testFor testSum suites suites.TestSuite 2 Error in file 'F:\dist\suites\TestSuite_2.robot' on line 6: Library '..\..\execution\Local\common\sum.py' does not exist. Error in file 'F:\dist\suites\TestSuite_2.robot' on line 7: Variable file '..\..\execution\Lib\Variables.py' does not exist. Error in file 'F:\dist\suites\TestSuite_2.robot' on line 8: Resource file '..\resources\source1.robot' does not exist. Error in file 'F:\dist\suites\TestSuite_2.robot' on line 9: Resource file '..\resources\source2.txt' does not exist. Error in file 'F:\dist\suites\TestSuite_2.robot' on line 6: Library '..\..\execution\Local\common\sum.py' does not exist. Error in file 'F:\dist\suites\TestSuite_2.robot' on line 7: Variable file '..\..\execution\Lib\Variables.py' does not exist. Error in file 'F:\dist\suites\TestSuite_2.robot' on line 8: Resource file '..\resources\source1.robot' does not exist. Error in file 'F:\dist\suites\TestSuite_2.robot' on line 9: Resource file '..\resources\source2.txt' does not exist.

The statistics section generated in the “kw” section in the beginning. This is wrong.
So I confused, in which situation, when I run the test cases and then generated the wrong “output.xml”.

No idea why but googling for similar issues all lead to Pabot - and at least one of those scenarios, person asking mentioned that there was version issues on his side…

Seems that multiple processes or possibly threads are writing to the same output.xml file. With this information alone it’s impossible for us to know why that happens.

It seems like that:
with open(os.path.join(self.report_path,‘templog.txt’), ‘w’) as stdout:
run(self.filepath, name=self.casename, test = test, outputdir = self.report_path, log=None, report = None,
stderr=stdout, stdout=stdout, loglevel = ‘TRACE’)

time.sleep(0.3)
resultfile = open(os.path.join(self.report_path,'output.xml'), "r")

After “run”, I tried to open ‘output.xml’ for other using.
Then I tried to give 0.3s sleep, it seems fine now.