No option to exclude imported but not used modules

Issue #643 closed
Abel Asefa created an issue

If the module is imported every function def will be declared as covered. A command line or API option should be available to exclude from reporting such kind of coverages.

Comments (7)

  1. Ned Batchelder repo owner

    I understand this impulse, but I don't see a way to do it. As far as Python is concerned, the module was used. How would we decide that a module wasn't used? Lines in the module were executed.

    Also, I'm unclear why it's important to exclude these files from coverage? There really are lines of code there that really weren't run. Don't you want to know about that? Isn't that the whole point of coverage measurement?

  2. Abel Asefa reporter

    Yeah, python executing while importing makes it tricky to do it.

    I wanted this option because I am trying to check if there are dead codes(using coverage as a way of finding dead codes).

  3. Ned Batchelder repo owner

    I would think the coverage report including these files would help you to find unused code? Also, look into pylint, which can report on imports that are never used.

  4. Abel Asefa reporter

    Thanks, I will look into it. One more thing is there a way to filter out coverage reports based on the coverage. For example, report only if coverage < 50%

  5. Ned Batchelder repo owner

    You can generate a report with the --fail-under setting, and then use the success or failure of the command to decide what to do with the report.

  6. Abel Asefa reporter

    That is a good option. But what we actually need is something similar but different. For example, if you see the attached snapshot(Sorry I couldn't post the paths due to confidentiality) there are lots of files which shows 0% coverage. I don't want to include those files in my report, I only want to see a file with coverage > 0%. Is there a way to do this?

    Capture.PNG

  7. Log in to comment