Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No option to exclude imported but not used modules #643

Open
nedbat opened this issue Feb 22, 2018 · 6 comments
Open

No option to exclude imported but not used modules #643

nedbat opened this issue Feb 22, 2018 · 6 comments
Labels
enhancement New feature or request

Comments

@nedbat
Copy link
Owner

nedbat commented Feb 22, 2018

Originally reported by Abel Asefa (Bitbucket: abelandk, GitHub: abelandk)


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.


@nedbat
Copy link
Owner Author

nedbat commented Feb 22, 2018

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?

@nedbat
Copy link
Owner Author

nedbat commented Feb 22, 2018

Original comment by Abel Asefa (Bitbucket: abelandk, GitHub: abelandk)


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).

@nedbat
Copy link
Owner Author

nedbat commented Feb 22, 2018

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.

@nedbat
Copy link
Owner Author

nedbat commented Feb 22, 2018

Original comment by Abel Asefa (Bitbucket: abelandk, GitHub: abelandk)


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%

@nedbat
Copy link
Owner Author

nedbat commented Feb 22, 2018

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.

@nedbat
Copy link
Owner Author

nedbat commented Feb 22, 2018

Original comment by Abel Asefa (Bitbucket: abelandk, GitHub: abelandk)


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

@nedbat nedbat removed the 4.5 label Aug 17, 2018
@nedbat nedbat removed the major label Jan 18, 2020
@nedbat nedbat added enhancement New feature or request and removed proposal labels Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant