Skip to content

Fix branch coverage rate comparison when used with --branch without actual branches #37

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

Merged
merged 5 commits into from
Mar 26, 2025

Conversation

marcegeek
Copy link
Contributor

When --branch option is set but there are no branches coverage.xml will contain 0 branches (branches-valid="0" and branches-covered="0") but have branch-rate="1". Fixes #23

…ut there are no branches

When `--branch` option is set but there are no branches `coverage.xml` will contain 0 branches
but have branch-rate="1". Fixes smarie#23
@marcegeek marcegeek changed the title Fix branch coverage rate comparison when used with --branch without actual branches Fix branch coverage rate comparison when used with --branch without actual branches. Fixes #23 Aug 18, 2024
@marcegeek marcegeek changed the title Fix branch coverage rate comparison when used with --branch without actual branches. Fixes #23 Fix branch coverage rate comparison when used with --branch without actual branches Aug 18, 2024
@smarie
Copy link
Owner

smarie commented Mar 21, 2025

Thanks @marcegeek ! I just pushed a pr that should hopefully have fixed the layout and ci. would you mind updating this branch and push again ?

Comment on lines +170 to +172
# detect whether the --branch option were set or not
# so CoverageStats knows how to distinguish between them
cov.branch_option = cov.branches_valid > 0 or branch_rate == 1.0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick)
If branch_option is only computed based on the other two fields according to this formula, could we implement it as a @property instead of a field ? That way it would not need to be present in the constructor arguments, nor to be late-set here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, as cov.branch_rate is computed as a @property while the original branch-rate="1" and branches-valid="0" fields from the XML are what we need to discover whether the --branch option was set or not. Wouldn't that require to store the original branch_rate from the XML? As a _branch_rate/_original_branch_rate/_xml_branch_rate field maybe?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see your point. And I see that CoverageStats was already entirely implemented in this weird "init as none - then fill" pattern. I do not remember where this class was copied from but indeed making it "nice" would require to change all of it, not just this new feature.
Not worth the effort IMO :) let's keep it like this for now.

@smarie
Copy link
Owner

smarie commented Mar 24, 2025

Great, thanks @marcegeek ! Just one minor comment, otherwise this is "good to go" for me

@smarie smarie merged commit 886ad97 into smarie:main Mar 26, 2025
10 checks passed
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

Successfully merging this pull request may close these issues.

ValueError: Computed branch rate (0) is different from the one in the file (1.0)
2 participants