Failing to run coverage from inside a python script with command line parameters (or if you modify sys.argv)

1,506 views
Skip to first unread message

Sorin Sbârnea

unread,
Sep 15, 2010, 7:31:54 AM9/15/10
to Coverage.py Development
If I try to run os.system("coverage xml") after running nose in a
python script I do get:
"No data to report." This is happening even when I run coverage using
its API.

If I disable the call of nose I do get the desired results.

At first i assumed that this may be caused by a current directory
change made by nose so I added:
os.chdir(os.path.dirname(os.path.abspath(__file__))) - because I have
the .coverage file in the same directory as the py script (running
`coverage xml` from the command line works!)

But this did not solve the problem.

It looks that if by default "coverage xml" will fail to run if you
have command line parameters. In addition to this even if you try to
restore the sys.argv does not solve the problem.

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/control.py", line 568, in
xml_report
reporter.report(morfs, outfile=outfile, config=self.config)
File "/Library/Python/2.6/site-packages/coverage-3.4b2-py2.6-
macosx-10.6-universal.egg/coverage/xmlreport.py", 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/report.py", line 72, in
report_files
raise CoverageException("No data to report.")
coverage.misc.CoverageException: No data to report.

The problem is more important because in order to provide some
arguments to nosetests you have to alter the sys.argv before running
nose ("-w" option is available only from the command line)

Thanks,

Arve Knudsen

unread,
Sep 15, 2010, 10:46:18 AM9/15/10
to coverag...@googlegroups.com
Hi Sorin

I've tried running first Nose and then "coverage xml" via os.system in the same script, and it works just fine for me. Both are the latest revision from their respective Mercurial repositories. Could you perhaps provide a simple self-contained case (i.e., script to drive Nose/Coverage.py, tests) that breaks for you? 

Arve

Ned Batchelder

unread,
Sep 17, 2010, 7:06:45 AM9/17/10
to coverag...@googlegroups.com, Arve Knudsen
Reply all
Reply to author
Forward
0 new messages