Skip to content

py39: branch coverage reports uncovered return branch #1041

Open
@a-feld

Description

@a-feld

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions