-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix XML comparison, compare time within 1e-6 seconds #63
base: main
Are you sure you want to change the base?
Conversation
There appears to be a difference in how 'time' is generated in the XML output, possibly different in different systems/configurations. Possible culprit is how the 'time' attribute is for 'testsuite' elements. https://github.com/kyrus/python-junit-xml/blob/4bd08a272f059998cedf9b7779f944d49eba13a6/junit_xml/__init__.py#L135 Test case attributes appear to be formatted using `'%f' % time`, which is 6 decimal places by default. For the testsuite, it looks like it's just a `str` call and maybe this is causing different systems to generate time of different precision. Due to this small differences in how time is encoded in the XML, the test suite may fail due to differences in the amount of precision is encoded on the system. Add a new function to the test suite that compares the XML document recursively and assert that tags, text and attributes match. For 'time' attributes, we compare using `math.isclose()` with a tolerance of 1e-6.
Hi @CervEdin can you fix the ruff issue with the xml module?
from defusedxml documentation: Instead of: >>> from xml.etree.ElementTree import parse
>>> et = parse(xmlfile) alter code to: >>> from defusedxml.ElementTree import parse
>>> et = parse(xmlfile) |
also I don't think this works:
tap2junit/test/output/test.xml Lines 2 to 3 in 0601e2d
<?xml version="1.0" encoding="utf-8"?>
-<testsuites disabled="0" errors="1" failures="0" tests="2367" time="1.1381459999999999">
- <testsuite disabled="0" errors="1" failures="0" name="test/fixtures/test3" skipped="25" tests="2367" time="1.1381459999999999" hostname="{HOSTNAME}">
+<testsuites disabled="0" errors="1" failures="0" tests="2367" time="1.138146">
+ <testsuite disabled="0" errors="1" failures="0" name="test3" skipped="25" tests="2367" time="1.138146" hostname="{HOSTNAME}">
<testcase name="test-async-await" time="0.000601" classname="async-hooks"/> |
% suspicious-xml-element-tree-usage (S314)Derived from the flake8-bandit linter. What it doesChecks for uses of insecure XML parsers. Why is this bad?Many XML parsers are vulnerable to XML attacks (such as entity expansion), Consider using the Examplefrom xml.etree.ElementTree import parse
tree = parse("untrusted.xml") # Vulnerable to XML attacks. Use instead: from defusedxml.ElementTree import parse
tree = parse("untrusted.xml") References |
@nicola-lunghi I guess there are two options here
I personally don't see the security issue here since the XML is trusted but option 1 is not bad per se
Sorry but I didn't follow what you meant here. Is something failing? Could be that epsilon needs tweaking. |
@cclauss thanks for the references I wonder if it applies in this case. The XML being parsed is 1) the xml files checked into the repo 2) the xml generated from tap files checked in to the repo and processed by |
There appears to be a difference in how 'time' is generated in the XML output, possibly different in different systems/configurations.
#62
Possible culprit is how the 'time' attribute is for 'testsuite' elements. https://github.com/kyrus/python-junit-xml/blob/4bd08a272f059998cedf9b7779f944d49eba13a6/junit_xml/__init__.py#L135
Test case attributes appear to be formatted using
'%f' % time
, which is 6 decimal places by default.For the testsuite, it looks like it's just a
str
call and maybe this is causing different systems to generate time of different precision.Due to this small differences in how time is encoded in the XML, the test suite may fail due to differences in the amount of precision is encoded on the system.
Add a new function to the test suite that compares the XML document recursively and assert that tags, text and attributes match.
For 'time' attributes, we compare using
math.isclose()
with a tolerance of 1e-6.