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

Goal Zero: Turn on branch coverage for pytest-cov #1394

Closed
sztamas opened this issue Aug 19, 2020 · 2 comments
Closed

Goal Zero: Turn on branch coverage for pytest-cov #1394

sztamas opened this issue Aug 19, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@sztamas
Copy link
Collaborator

sztamas commented Aug 19, 2020

Using --cov-branch will reveal a few branches that aren't reached when pytesting the project.

Just to state the obvious, having a less than 100% coverage shows that the tests don't cover all the code-base for sure, but the reverse isn't true - having 100% coverage doesn't mean that the test coverage is good enough. Covering all the lines and branches, doesn't mean that your tests are verifying all the possible outcomes.

To illustrate just for fun :-)

Given this function:

def rest(xs: list):
    if xs is None or len(xs) <= 1:
        return []
    return xs[1:]

Running this test will report a 100% branch coverage:

def test_rest():
    assert rest([]) == []
    assert rest([1, 2]) == [2]

Although there is no test for passing in None, a list with 1 element etc.

Or to make the example more extreme this is 100% as well:

def test_rest():
    rest([]) == []
    rest([1, 2]) == [2]

While removing the assertions completely looks silly, it highlights the problem that the test is as good as your assertions are.

@timothycrosley
Copy link
Member

I'm open to changing this, but only after the project achieves 100% branch coverage (which may be in reach after the other testing tickets are resolved). The reason being that the 100% coverage level (currently calculated by lines) acts as very recognizable and easily understood quality bar for all PRs and the project itself. Once the coverage goes below that, it's easier to be complacent. If we can get to 100% branch coverage, all the better! I'd be happy to raise the bar to that level.

@timothycrosley timothycrosley added the enhancement New feature or request label Aug 20, 2020
@timothycrosley timothycrosley changed the title Consider turning on branch coverage for pytest-cov Goal Zero: Turn on branch coverage for pytest-cov Aug 25, 2020
@timothycrosley
Copy link
Member

This is finally implemented in the main branch 🎉

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

No branches or pull requests

2 participants