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

py39: branch coverage reports uncovered return branch #1041

Open
a-feld opened this issue Oct 13, 2020 · 2 comments
Open

py39: branch coverage reports uncovered return branch #1041

a-feld opened this issue Oct 13, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@a-feld
Copy link

a-feld commented Oct 13, 2020

Describe the bug

Coverage reports return statement as uncovered when branch coverage is enabled in py39.

image

To Reproduce

example.py

def main():
    try:
        return object()
    finally:
        try:
            pass
        except:
            pass

main()

command

coverage run --branch example.py && coverage html

environment

Python Version: Python 3.9.0
coverage.py version: Coverage.py, version 5.3 with C extension (although without C extension reports the same results)

Expected behavior

coverage reports the return statement as covered in Python 3.9, the same as Python 3.8

Additional context

From what I can see, the disassembly of main in example.py is different in py38 versus py39
Coverage is expecting an arc from the return statement to the first code line. In py38, this arc occurs. In py39, this arc does not occur.

When using sys.settrace with a debug function, the outputs are different between py38 and py39.

import sys

from example import main


def trace(frame, event, arg):
    lineno = frame.f_lineno
    print(event, lineno)
    return trace


sys.settrace(trace)
main()

py38 output:

call 1
line 2
line 3
line 5
line 6
line 3
return 3

py39 output:

call 1
line 2
line 3
line 5
line 6
return 6
@a-feld a-feld added the bug Something isn't working label Oct 13, 2020
@tirkarthi
Copy link
Contributor

On bisecting this seems to have been due to changes made in python/cpython#6641

@yaythomas
Copy link

thanks for a detailed bug report @a-feld and analysis @tirkarthi! you both just saved me a lot of digging! 🙌

I'm dealing with something similar here https://github.com/pypyr/pypyr/blob/d4a36f0dbf6a3e47773dadfb8deebd73aa1e0bcf/pypyr/dsl.py#L463

Code is definitely covered and used to pass 100% covered with py 3.6 through to py 3.8.

As of py 3.9, reports 463->exit as uncovered.

miketheman added a commit to miketheman/warehouse that referenced this issue Feb 23, 2022
In the move to Python 3.9, we are subject to a coverage behavior that
has yet to be corrected.
In the interest of keeping the coverage report to 100%, we exclude
the statement that coverage.py reports as not being executed, despite
it being executed via tests.

Refs: nedbat/coveragepy#1041

Signed-off-by: Mike Fiedler <[email protected]>
ewdurbin pushed a commit to pypi/warehouse that referenced this issue Feb 23, 2022
* chore: update local/CI execution to Python 3.9

For the development (outer) environment,
update to Python 3.9.10 - latest as of this writing.

Signed-off-by: Mike Fiedler <[email protected]>

* chore: upgrade python version

Move us to 3.9.10 - latest release.

Signed-off-by: Mike Fiedler <[email protected]>

* chore: update requrements hashes for python3.9

* test: exclude statement from coverage report

In the move to Python 3.9, we are subject to a coverage behavior that
has yet to be corrected.
In the interest of keeping the coverage report to 100%, we exclude
the statement that coverage.py reports as not being executed, despite
it being executed via tests.

Refs: nedbat/coveragepy#1041

Signed-off-by: Mike Fiedler <[email protected]>

Co-authored-by: Dustin Ingram <[email protected]>
domdfcoding pushed a commit to domdfcoding/warehouse that referenced this issue Jun 7, 2022
* chore: update local/CI execution to Python 3.9

For the development (outer) environment,
update to Python 3.9.10 - latest as of this writing.

Signed-off-by: Mike Fiedler <[email protected]>

* chore: upgrade python version

Move us to 3.9.10 - latest release.

Signed-off-by: Mike Fiedler <[email protected]>

* chore: update requrements hashes for python3.9

* test: exclude statement from coverage report

In the move to Python 3.9, we are subject to a coverage behavior that
has yet to be corrected.
In the interest of keeping the coverage report to 100%, we exclude
the statement that coverage.py reports as not being executed, despite
it being executed via tests.

Refs: nedbat/coveragepy#1041

Signed-off-by: Mike Fiedler <[email protected]>

Co-authored-by: Dustin Ingram <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants