Coverage fails to run invoking improperly 'No data to report'

Issue #91 invalid
Sorin Ionuț Sbârnea created an issue

If you call coverage using Python API, coverage will fail to throwing the below error if you call the script with command line arguments or if you modify sys.argv.

It looks that you cannot start coverage without command line parameters.

{{{ Traceback (most recent call last): File "./", line 31, in <module> do_coverage() File "./", line 18, in do_coverage cov.xml_report(ignore_errors=True, outfile='coverage.xml') File "/Library/Python/2.6/site-packages/coverage-3.4b2-py2.6-macosx-10.6-universal.egg/coverage/", line 568, in xml_report, outfile=outfile, config=self.config) File "/Library/Python/2.6/site-packages/coverage-3.4b2-py2.6-macosx-10.6-universal.egg/coverage/", line 57, in report self.report_files(self.xml_file, morfs, config) File "/Library/Python/2.6/site-packages/coverage-3.4b2-py2.6-macosx-10.6-universal.egg/coverage/", line 72, in report_files raise CoverageException("No data to report.") coverage.misc.CoverageException: No data to report. }}}

Comments (4)

  1. Ned Batchelder repo owner

    Thanks for the report, but I could use some more details. Ideally, you'd attach a tarball that demonstrates the problem. At least, could you show me the Python code you use to invoke coverage, and a bit of the code under test?

  2. Ned Batchelder repo owner

    The problem here is that you are running nose in-process, and it doesn't write the .coverage file until the end of the process. When you call xml_report, the data file hasn't been written to disk yet, and so it finds nothing to report.

    Unfortunately, there doesn't seem to be a clean way to do what you want. This works, but uses internal details of

    	from coverage import _the_coverage
    	_the_coverage.xml_report(ignore_errors=True, outfile='mycov.xml')

    Use this instead of the import coverage... coverage.xml_report code you have, and it will create the XML report you want.

    I'm not sure whether to count this as a bug against or not. You're mixing two different APIs in a way they weren't intended to be mixed.

  3. Log in to comment