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

python3.8 try-finally-return reports wrong branch coverage with async functions #964

afflux opened this issue Mar 24, 2020 · 1 comment
bug Something isn't working


Copy link

afflux commented Mar 24, 2020

Describe the bug
I'm afraid I have a similar case to #707, although somehow, decorators and coroutine functions are involved.

To Reproduce

  1. What version of Python are you using? python3.8
  2. What version of are you using? 5.0.4., sys.txt attached
  3. What versions of what packages do you have installed? pip-freeze.txt
  4. What commands did you run? coverage run --branch ; coverage html
  5. What code are you running?
import asyncio

def foo(x):
    return x

async def f1():
        return 2

Expected behavior
Full branch coverage for f1()

Additional context
systrace has frame.f_code.co_firstlineno on the line with the @foo decorator.
When f1 is async, AstArcAnalyzer finds an arc to the line containing async def:

Adding arc: (11, -9): "the return on line {lineno} wasn't executed", "didn't return from function 'f1'"
     _code_object__FunctionDef : /home/kb/repos/pysomeip/.tox/coverage/lib/python3.8/site-packages/coverage/
                 add_body_arcs : /home/kb/repos/pysomeip/.tox/coverage/lib/python3.8/site-packages/coverage/
                      add_arcs : /home/kb/repos/pysomeip/.tox/coverage/lib/python3.8/site-packages/coverage/
                  _handle__Try : /home/kb/repos/pysomeip/.tox/coverage/lib/python3.8/site-packages/coverage/
          process_return_exits : /home/kb/repos/pysomeip/.tox/coverage/lib/python3.8/site-packages/coverage/
                       add_arc : /home/kb/repos/pysomeip/.tox/coverage/lib/python3.8/site-packages/coverage/

If I make f1 non-async, AstArcAnalyzer finds the line with the decorator:

Adding arc: (11, -8): "the return on line {lineno} wasn't executed", "didn't return from function 'f1'"
[same stack]
@afflux afflux added the bug Something isn't working label Mar 24, 2020
afflux added a commit to afflux/coveragepy that referenced this issue Mar 24, 2020
@nedbat nedbat closed this as completed in 0db15a2 Mar 26, 2020
nedbat added a commit that referenced this issue Mar 26, 2020
handle decorators for AsyncFunctionDefs. Closes #964
Copy link

nedbat commented Apr 12, 2020

This is available in 5.1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
bug Something isn't working
None yet

No branches or pull requests

2 participants