interpretion of branch coverage

58 Views Asked by At

This is kind of an followup question to How do I interpret Python coverage.py branch coverage results?

I have a different situation where I check a variable perr which has in different scenarios, which I am testing could be either an empty List or a List[str].

The code looks similar to this:

if perr:
    message = self.trim_password_prompt(perr[0])
    if len(message):
        raise SystemError(f"{message}")

return pout

Assuming that the if-statement is at line 92 and the return-statement on line 97, the Missing Branch is listed as 92->97.

I have different if-statements in my code, which are successful tested in multiple tests.

I don't understand after all the things I was reading, why the coverage fails here, since I have tests, which are reaching both lines.

1

There are 1 best solutions below

0
On

I read over and over through the documentation of pytest and according articles. I came to the resume the documentation includes no actual information about what branch coverage actually is or link at least to relevant information.

I was at least able to find some further and straight forward informations, which gave me a hint, what branch coverage actually is testing:

https://www.cs.odu.edu/~cs252/Book/branchcov.html

After reading this few lines, I think I understand the issue. pytest could at this point better document this.

Sadly I wasn't able to test my actually code against this knowledge with reasonable effort.

So based on that, I came to the following conclusion:

For some reason, I am unable to control, the value of perr never results in false in my tests. Since line 97 is tested nevertheless, the statement testing is completed for all lines, but the jump from line 92->97 has never occurred.

If my statements are correct, I am fine with the result, since mocking is not reasonable from my standpoint.