aconrad / pycobertura

A code coverage diff tool for Cobertura reports
MIT License
114 stars 39 forks source link

'NoneType' object has no attribute 'has_file' #171

Open dimaqq opened 1 year ago

dimaqq commented 1 year ago

I'm trying to diff a couple of files generated by python coverage tool and converted to XML.

I get an exception here:

    383 def file_source(self, filename):
    384     """
    385     Return a list of namedtuple `Line` for each line of code found in the
    386     given file `filename`.
    387 
    388     """
--> 389     if self.cobertura1.has_file(filename) and self.cobertura1.filesystem.has_file(
    390         filename
    391     ):
    392         lines1 = self.cobertura1.source_lines(filename)
    393         line_statuses1 = dict(self.cobertura1.line_statuses(filename))

AttributeError: 'NoneType' object has no attribute 'has_file'

Somehow the 2nd clause, self.cobertura1.filesystem is None.

aconrad commented 1 year ago

Thanks for reporting. Can you provide the command line you used to get this error?

dimaqq commented 1 year ago

Not a command, I tried https://github.com/aconrad/pycobertura/blob/22b6d34d828cd6dedf8b69203e5f8e158086a802/README.md?plain=1#L393

In the end I've worked around it by passing a filesystem smth object to the cobertura constructor.

I guess the readme can be updated

aconrad commented 1 year ago

Ah, I see. I'll take a look at the README this coming week.

kumarak-deshaw commented 6 months ago

FTR, it works if the cobertura instantiation has filesystem arg

cobertura1 = Cobertura(xml1, filesystem=filesystem_factory(xml1, source_prefix))
cobertura2 = Cobertura(xml2, filesystem=filesystem_factory(xml2, source_prefix))
reporter = HtmlReporterDelta(cobertura1, cobertura2, show_source=True)
reporter.generate()