Skip to content
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

Can't generate xml report if some source file's path has unicode characters #573

nedbat opened this issue Apr 12, 2017 · 2 comments
bug Something isn't working xml


Copy link

nedbat commented Apr 12, 2017

Originally reported by Dongmin Kim (Bitbucket: kim135797531, GitHub: kim135797531)

If source file's path has any unicode characters in it, the dump into the xml will fail on Python 2.

~/temp/$ coverage xml # No error.
~/temp/테스트/$ coverage xml # Error.

/usr/lib/python2.7/ UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  s1 = min(m)
Traceback (most recent call last):
  File "/usr/local/bin/coverage", line 11, in <module>
  File "/usr/local/lib/python2.7/dist-packages/coverage/", line 756, in main
    status = CoverageScript().command_line(argv)
  File "/usr/local/lib/python2.7/dist-packages/coverage/", line 517, in command_line
    total = self.coverage.xml_report(outfile=outfile, **report_args)
  File "/usr/local/lib/python2.7/dist-packages/coverage/", line 1070, in xml_report
    return, outfile=outfile)
  File "/usr/local/lib/python2.7/dist-packages/coverage/", line 76, in report
    self.report_files(self.xml_file, morfs)
  File "/usr/local/lib/python2.7/dist-packages/coverage/", line 91, in report_files
    report_fn(fr, self.coverage._analyze(fr))
  File "/usr/local/lib/python2.7/dist-packages/coverage/", line 166, in xml_file
    xclass.setAttribute("name", os.path.relpath(rel_name, dirname))
  File "/usr/lib/python2.7/", line 441, in relpath
    i = len(commonprefix([start_list, path_list]))
  File "/usr/lib/python2.7/", line 71, in commonprefix
    s1 = min(m)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xed in position 0: ordinal not in range(128)

Line 168 in coverage/ makes this exception. It seems to problem of unicode handling issue with Python 2.

Anyway I could fix this problem by casting dirname to unicode. This fix is a kind of quick hack, so I hope this suggestion helps to find the root cause of this problem.

        xlines = self.xml_out.createElement("lines")

        # Fix for unicode error.
        if env.PY2:
            dirname = unicode(dirname)
        xclass.setAttribute("name", os.path.relpath(rel_name, dirname))
        xclass.setAttribute("filename", fr.relative_filename().replace("\\", "/"))
        xclass.setAttribute("complexity", "0")

Copy link
Owner Author

nedbat commented Apr 30, 2017

Thanks for the report. The fix was even easier: 1da80e5bbdd5 (bb)

Copy link
Owner Author

nedbat commented Apr 30, 2017

Original comment by Dongmin Kim (Bitbucket: kim135797531, GitHub: kim135797531)

Thanks! 👍

@nedbat nedbat closed this as completed Apr 30, 2017
@nedbat nedbat added major bug Something isn't working xml labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
bug Something isn't working xml
None yet

No branches or pull requests

1 participant