Skip to content

Instantly share code, notes, and snippets.

@rplevka
Last active November 3, 2020 14:54
Show Gist options
  • Save rplevka/36917d4415aa2816433d1162b780b01d to your computer and use it in GitHub Desktop.
Save rplevka/36917d4415aa2816433d1162b780b01d to your computer and use it in GitHub Desktop.
fix junit.xml start_time properties
import os
import time
import xmltodict
files = os.listdir('.')
for fi in files:
if fi == 'new':
continue
with open(fi, 'r') as f:
foo = xmltodict.parse(f.read())
t = foo['testsuites']['testsuite']['@timestamp']
to = time.strptime(t.split('.')[0]+'_+0200', '%Y-%m-%dT%H:%M:%S_%z')
epoch = time.mktime(to) - 7200
to = time.gmtime(epoch)
tn = f'{to.tm_year}-{to.tm_mon}-{to.tm_mday}T{to.tm_hour-2}:{to.tm_min}:{to.tm_sec}'
foo['testsuites']['testsuite'].update({'properties': [{'property': {'@name': 'start_time', '@value': tn}}]})
with open(f'new/{fi}', 'w') as g:
g.write(xmltodict.unparse(foo))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment