In a pytest coverage report, what does "->" mean for missing lines?
Asked Answered
K

2

8

I'm running pytest with the coverage plugin (pytest --cov) and in the report I got the following line:

Name          Stmts   Miss Branch BrPart  Cover   Missing
---------------------------------------------------------
foo.py            5      1      2      1    71%   3->5, 5

I know that 3-5 would mean it missed lines 3 to 5, but I don't know what -> means. From the test logic, I'd expect only 5 to be reported. For reference, this is the code I used:

# foo.py

class Test:
    def __lt__(self, other):
        if type(self) == type(other):
            return False
        return NotImplemented


# test_foo.py

def test_lt():
    test = Test()
    assert not (test < test)
Keelung answered 17/10, 2020 at 20:20 Comment(0)
C
7

Coverage collects pairs of transition in your code that goes from one line (the source) to another (the destination). In some cases, some transitions could be jumped, like in conditional statements or a break statememt, then it would be measured as a missing branch (or missing transition).

For example, in your code there is one transition that can be jumped.

if type(self) == type(other):
       return False
   return NotImplemented

see that from line 3 to line 5 is a transition that can not necessarily happen as there could be the case that the if statement don't evaluate to False. Thus, branch coverage will flag this code as not fully covered because of the missing jump from line 3 to line 5.

References

How does branch coverage works. https://coverage.readthedocs.io/en/latest/branch.html#how-it-works

Cheat answered 17/10, 2020 at 20:53 Comment(0)
W
1

I assumed you enabled branch coverage. Basically, according to the post in the link, 3->5 just means the branching that jump from line 3 to line 5, which in your case, it's referring to when this if type(self) == type(other) is false and jump directly to return NotImplemented(which never happened in your test case).

credit to this question, How do I interpret Python coverage.py branch coverage results?

Woo answered 17/10, 2020 at 20:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.