Function declaration line shows as not executed

Issue #28 invalid
Jeremy Whitlock created an issue

The coverage report for my app shows a function's contents as executed but says the line declaring the function was not. Here is an example:

{{{ #!python class Person(object): def init(self, name): = name

def speak(self, msg):


and here is an example usage during my coverage process:

{{{ #!python ... p = Person("Jeremy") p.speak("I like") }}}

While this is purely an example, the report would tell me that lines 3 and 6 executed but not lines 2 and 5. I just updated to the latest version and I get the same result. (I tried with 3.0.1 and 3.1.)

I'm also seeing global-level comments and imports not being shown as executed either. So if I have:

{{{ #!python # # --python-- # """This is where the database code goes."""

import os, sys

... }}}

I end up with my report telling me lines 4-6 were not executed.

I've used this for a few Django-based projects before and never ran into problems like this and while it could be bad Python structure and/or user error, I figured this would be the place to start.

Comments (4)

  1. Jeremy Whitlock reporter
    • changed version to 3.1

    I forgot to set the version. I was able to reproduce this in 3.1 and 3.0.1.

  2. Jeremy Whitlock reporter

    Ned, Please forgive me. I'm usually pretty good at reading before assuming there is a problem. I am using the API and I bet that I'm not starting code coverage before the class is imported. Let me try again and I'll let you know.

  3. Jeremy Whitlock reporter

    That fixed it. If I put the coverage.start() call before importing my tests, I get the proper coverage numbers. Sorry for the false alarm.

  4. Log in to comment