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

Wrong branch coverage for Python 3.8 in try-return-finally #707

Closed
lhupfeldt opened this Issue Sep 16, 2018 · 13 comments

Comments

2 participants
@lhupfeldt

lhupfeldt commented Sep 16, 2018

Given the following program:

_val = None

def return_from_try_finaly(early):
    global _val
    _val = 1
    try:
        orig_val = _val
        _val = 2
        if early:
            return 1
    finally:
        _val = orig_val

    return 3


assert return_from_try_finaly(True) == 1
assert _val == 1

assert return_from_try_finaly(False) == 3
assert _val == 1

stored in try_return_finally.py

Shows full coverage for python 3.6:

$ python=python3.6; $python -m coverage run try_return_finally.py && $python -m coverage report -m
Name                    Stmts   Miss Branch BrPart      Cover   Missing
-----------------------------------------------------------------------
try_return_finally.py      14      0      4      0   100.000%

Partial branch for python 3.8:

$ python=python3.8; $python -m coverage run try_return_finally.py && $python -m coverage report -m
Name                    Stmts   Miss Branch BrPart      Cover   Missing
-----------------------------------------------------------------------
try_return_finally.py      14      0      4      1    94.444%   12->exit
@nedbat

This comment has been minimized.

Owner

nedbat commented Sep 16, 2018

Hmm, looks like something has changed since 3.7... Running the whole test suite on latest 3.8 shows these failures:

FAIL tests/test_arcs.py::ExceptionArcTest::test_break_through_finally
FAIL tests/test_arcs.py::ExceptionArcTest::test_else_jump_finally
FAIL tests/test_arcs.py::LoopArcTest::test_zero_coverage_while_loop
FAIL tests/test_arcs.py::ExceptionArcTest::test_continue_through_finally
FAIL tests/test_arcs.py::LoopArcTest::test_bug_496_continue_in_constant_while
FAIL tests/test_arcs.py::ExceptionArcTest::test_except_jump_finally
FAIL tests/test_arcs.py::ExceptionArcTest::test_return_finally
FAIL tests/test_arcs.py::LoopArcTest::test_while_true
FAIL tests/test_arcs.py::ExceptionArcTest::test_bug_212
FAIL tests/test_concurrency.py::ConcurrencyTest::test_threads
FAIL tests/test_html.py::HtmlGoldTests::test_partial
@nedbat

This comment has been minimized.

Owner

nedbat commented Sep 16, 2018

I've asked the core devs for an opinion: https://bugs.python.org/issue34705

@lhupfeldt

This comment has been minimized.

lhupfeldt commented Oct 2, 2018

Hi again Ned,

In the latest version of Python 3.8 (11c4eaa99362f91c7faea88e31df3e46af020023) coverage is very broken, you can see here: https://travis-ci.org/lhupfeldt/multiconf/jobs/436314142.

I have 100% coverage on Python 3.6 and 3.7. All these coverage errors are new, they were not there when I created this issue with an earlier version of Python 3.8.

Sorry I don't have time to dig into it and provide examples right now.

You might want to alert core devs again.

@lhupfeldt

This comment has been minimized.

lhupfeldt commented Oct 2, 2018

multiconf/envs.py 210 37 82 2 86.644% 313-1149, 91->125, 92->91
This file only has 307 lines, something has gone completely wrong.

@nedbat

This comment has been minimized.

Owner

nedbat commented Oct 2, 2018

This is actually a different cause than the original problem. The phantom lines are due to a change in the lnotab table that was made in Python 3.6, but hasn't been used until now. The phantom line problem is a simple fix that I have to decide how to ship.

@nedbat

This comment has been minimized.

Owner

nedbat commented Oct 4, 2018

The phantom line issue is #714

@nedbat

This comment has been minimized.

Owner

nedbat commented Oct 6, 2018

@lhupfeldt I've made some fixes. Can you try installing from GitHub to see if it works for you?

pip install git+https://github.com/nedbat/coveragepy.git@nedbat/v4.5.x#egg=coverage==0.0
@lhupfeldt

This comment has been minimized.

lhupfeldt commented Oct 6, 2018

Both the try-finally and the phantom lines issues are solved. Thank you.

Using pip install with the link did not work though, I ran python3.8 setup.py install from commit 51aacdb instead.

@lhupfeldt

This comment has been minimized.

lhupfeldt commented Oct 7, 2018

You had an extra 'nedbat' in pip install command, it should be:
pip install git+https://github.com/nedbat/coveragepy.git@v4.5.x#egg=coverage==0.0

@nedbat

This comment has been minimized.

Owner

nedbat commented Oct 7, 2018

Oops, thanks!

@lhupfeldt

This comment has been minimized.

lhupfeldt commented Oct 7, 2018

No problem.

@nedbat

This comment has been minimized.

Owner

nedbat commented Oct 16, 2018

Fixed in 04ff188 (for 5.0) and f12f855 (for 4.5.x)

@nedbat nedbat closed this Oct 16, 2018

@nedbat

This comment has been minimized.

Owner

nedbat commented Nov 12, 2018

This fix is in 4.5.2, just released: https://pypi.org/project/coverage/4.5.2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment