weiwei / junitparser

Parses JUnit/xUnit Result XML files with ease
https://junitparser.readthedocs.io
Other
120 stars 52 forks source link

JUnitXml.fromfile raises OSError if file is not found #91

Closed mcejp closed 2 years ago

mcejp commented 2 years ago

I suppose this behavior is inherited from LXML, but it still feels wrong -- one would expect a FileNotFoundError.

Traceback (most recent call last):
  File "my_code.py", line 35, in <module>
    xml = JUnitXml.fromfile("results.xml")
  File "/lib/python3.10/site-packages/junitparser/junitparser.py", line 322, in fromfile
    tree = etree.parse(filepath)  # nosec
  File "src/lxml/etree.pyx", line 3521, in lxml.etree.parse
  File "src/lxml/parser.pxi", line 1859, in lxml.etree._parseDocument
  File "src/lxml/parser.pxi", line 1885, in lxml.etree._parseDocumentFromURL
  File "src/lxml/parser.pxi", line 1789, in lxml.etree._parseDocFromFile
  File "src/lxml/parser.pxi", line 1177, in lxml.etree._BaseParser._parseDocFromFile
  File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 652, in lxml.etree._raiseParseError
OSError: Error reading file 'results.xml': failed to load external entity "results.xml"
weiwei commented 2 years ago

Yes that's indeed an issue from lxml. However, file system logic can get complex and I've decided that it's not in the scope of the library. I'll leave the user to validate beforehand if needed.

mcejp commented 2 years ago

ACK, thanks for your reply.