microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.29k stars 1.18k forks source link

Confusing test coverage numbers for conditionals #24181

Closed mjbvz closed 2 hours ago

mjbvz commented 4 hours ago

Testing #24160

I added some always false conditionals and am confused by the numbers being listed for coverage. Here's the code:

def increment(x):
    """Increment x by 1, but not above 10."""
    return x + 1

def decrement(x):
    """Decrement x by 1, but not below 0."""
    if False:
        return x - 1
    if False:
        return x - 1
    if False:
        return x - 1
    if False:
        return x - 1
    if False:
        return x - 1
    if False:
        return x - 1
    if False:
        return x - 1

    return 0

This shows 100% coverage with zero branches

Image

I know the code in these conditionals isn't reachable but these numbers seem misleading

eleanorjboyd commented 2 hours ago

This comes from coverage.py and how it works so this is an upstream issue more with coverage in general. Closing as its not something I can control