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

Ignore partial lines in the coverage report percentage #624

Open
sebas031811 opened this issue Dec 6, 2023 · 3 comments
Open

Ignore partial lines in the coverage report percentage #624

sebas031811 opened this issue Dec 6, 2023 · 3 comments

Comments

@sebas031811
Copy link

What's the problem this feature will solve?

Is there an option to ignore partial lines in the coverage report? Currently, we compare the coverage report with Codecov, which already ignores partial lines in the coverage report.
Currently, pytest treats a partial line as half of a covered line when calculating the coverage percentage in the report.

Describe the solution you'd like

We request a feature or flag to exclude partial lines when calculating coverage percentages in the report.

In the first image, we have an 86.67% of coverage for the file src/logger.py, but in the second image we have 84.62%

image

image

Alternative Solutions

There is an option # pragma: no branch to ignore lines in the coverage report. But we should put it in every partial line.

@nicoddemus nicoddemus transferred this issue from pytest-dev/pytest Dec 6, 2023
@nedbat
Copy link
Collaborator

nedbat commented Dec 7, 2023

What do you mean by a partial line? Why do you want to ignore them? Maybe you don't want branch coverage at all, and just line coverage?

@sebas031811
Copy link
Author

Hello! A 'partial line' refers to a situation in code coverage where only a portion of a line is covered by tests. This can happen, for instance, in an 'if' statement where only one branch is covered. The line containing the 'if' statement is marked as partial, contributing to a coverage percentage.

The reason for wanting to ignore partial lines is to align the behavior with other CI coverage reporters like Codecov. Codecov typically ignores these partial lines when calculating coverage percentages. When uploading the coverage report from pytest to Codecov, the differences in handling partial lines may lead to minor variations in coverage percentages between the two tools.

image

Interestingly, we've observed that using line coverage instead of branch coverage tends to magnify these differences. Ignoring partial lines can help maintain consistency and reduce discrepancies in coverage percentages across different reporting tools.

@nedbat
Copy link
Collaborator

nedbat commented Dec 7, 2023

I don't know what you mean by "ignore the partial lines". I assume you mean you want to treat them as 100% executed. That's what line coverage would do. Can you show an example of how line coverage magnifies the differences?

FWIW, it is not a goal for coverage.py (the engine that pytest-cov wraps) to somehow mimic other tools' calculations precisely. I want to make it the most useful tool it can be in its own right. If one tool says 91% and another tool says 92%, you might have too many tools, or you have to accept that they have differences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants