Skip to content

Conversation

@Ayisha-Mohammed
Copy link

This PR improves the partial branch coverage documentation by adding the missing examples.
Fixes #1597

@nedbat
Copy link
Member

nedbat commented Nov 20, 2025

Thanks for getting this started!

I think all the examples should be put in branch.rst, since they will be helpful for people looking at the HTML report also. You can put something in cmd_report.rst that explains what -> means, and reference the examples in branch.rst for more details.

For the formatting, try using make dochtml on your machine to see the finished HTML files. This can help you get the RST markup correct.

@Ayisha-Mohammed
Copy link
Author

@nedbat made changes as requested.

Copy link
Member

@nedbat nedbat left a comment

Choose a reason for hiding this comment

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

This is great. You've removed more text than I wanted you to, so we need to find the right balance.


The HTML report gives information about which lines had missing branches. Lines
that were missing some branches are shown in yellow, with an annotation at the
far right showing branch destination line numbers that were not exercised.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why you removed "at the far right". I thought people might not notice it at the edge that usually has no information, so I wanted to direct their attention there.

also include branch information, including separate statement and branch
coverage percentages.


Copy link
Member

Choose a reason for hiding this comment

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

I like having extra space before headings. Can we keep the double-blank lines?

flagged.

Generator expressions
=====================
Copy link
Member

Choose a reason for hiding this comment

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

This was meant to be a section within "Structurally partial branches", which is why it has a different header rule style.

doc/branch.rst Outdated
executions divided by the execution opportunities. Each line in the file is an
execution opportunity, as is each branch destination.
covered total for each file. Each line in the file is an execution opportunity,
as is each branch destination.
Copy link
Member

Choose a reason for hiding this comment

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

The last sentence mentions "execution opportunity", which was part of the sentence you dropped. I'm not sure the last sentence makes sense without it.

doc/branch.rst Outdated
will not be marked as a partial branch.
Here the ``while`` loop will never exit normally, so it doesn't take both of
its "possible" branches. For some of these constructs, such as ``while True:``
and ``if 0:``, coverage.py understands what is going on.
Copy link
Member

Choose a reason for hiding this comment

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

Again, I feel like something important is lost by dropping the last sentence of the paragraph.

doc/branch.rst Outdated
Missing:
12 -> 10

Coverage.py will report::
Copy link
Member

Choose a reason for hiding this comment

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

We can probably skip this, since you've already said "12 -> 10" just above.

Copy link
Author

Choose a reason for hiding this comment

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

you mean to remove the case2 block?

Copy link
Member

Choose a reason for hiding this comment

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

I meant that we show "12->10" here on line 164 but we already showed it on line 160. But this whole example needs to be re-thought.

doc/branch.rst Outdated

If ``flag`` is always true, the false branch is never taken.

The report will show::
Copy link
Member

Choose a reason for hiding this comment

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

we should include the word "missing" here somehow to underscore that the branches reported are the missing branches.

doc/branch.rst Outdated
A ``for`` loop has:

* ``20->21`` (enter body)
* ``21->20`` (repeat)
Copy link
Member

Choose a reason for hiding this comment

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

You used bullets here, but not above. We should choose a consistent style.

Missing branches
----------------

Missing branches are shown such as ``12->10``.why is it backward?
Copy link
Member

Choose a reason for hiding this comment

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

This make it sound like branches are always reported in reverse. We should be clear that it's only sometimes.


For detailed examples of how branch coverage works in loops and other control
flow constructs (``if/else``, ``for`` loops, ``while`` loops, ``try/except``),
see :doc:`branch </branch>`.
Copy link
Member

Choose a reason for hiding this comment

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

This reads as "see branch." which isn't the form we want. Use:

see :ref:`branch`.

@Ayisha-Mohammed
Copy link
Author

@nedbat i've made the changes you requested. Thank you for the guidance , learnt a lot though this process.

doc/branch.rst Outdated
Case 2 — ``items = [1]``::

Missing:
12 -> 10
Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry i didn't realize this earlier: this code doesn't have a branch from 12->10, because branches only occur where a statement can go next to two different places. Line 12 always goes to line 10, even on the last iteration of the loop. So we need to re-think this example.

Copy link
Author

Choose a reason for hiding this comment

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

@nedbat thank you , i fixed it

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.

Add explanation and examples for symbols used when displaying branch coverage

2 participants