Uncaught ZeroDivisionError when generating XML report

Issue #250 resolved
Chris Rebert created an issue

If you ask coverage v3.6 to generate an XML report under a no-meaningful-tests edge case, it crashes:

<nose portion of call stack elided>
  File "/var/lib/jenkins/shiningpanda/jobs/f9dc77ce/virtualenvs/d41d8cd9/lib/python2.7/site-packages/coverage/control.py", line 647, in xml_report
    return reporter.report(morfs, outfile=outfile)
  File "/var/lib/jenkins/shiningpanda/jobs/f9dc77ce/virtualenvs/d41d8cd9/lib/python2.7/site-packages/coverage/xmlreport.py", line 88, in report
    return 100.0 * (lhits_tot + bhits_tot) / (lnum_tot + bnum_tot)
ZeroDivisionError: float division by zero

Comments (3)

  1. Ned Batchelder repo owner

    @cvrebert I thought I understood what this report meant, but I can't reproduce it now. Can you give me more details? What does a "no-meaningful-tests edge case" mean? How are you running your tests, and your XML report?

  2. Chris Rebert reporter

    Sorry. Here's a more detailed testcase description:

    1. Create this directory+file structure:
    /foo/bar/__init__.py       [empty file]
    /foo/bar/test_foobar.py    [content given below]
    # /foo/bar/test_foobar.py
    from unittest import TestCase
    class MyTestCase(TestCase):
    1. Create a new Python 2.7 virtualenv, and activate it.
    2. Run pip install coverage nose
    3. With /foo/ as your working directory, run nosetests --with-xunit --with-coverage --cover-package=bar --cover-xml
    4. Observe that the command crashed with a traceback, due to a ZeroDivisionError in coverage.
  3. Log in to comment