Skip to content

AssertionRewriter breaks coverage #3689

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

Closed
bluefish6 opened this issue Jul 17, 2018 · 3 comments
Closed

AssertionRewriter breaks coverage #3689

bluefish6 opened this issue Jul 17, 2018 · 3 comments
Labels
topic: rewrite related to the assertion rewrite mechanism type: bug problem that needs to be addressed

Comments

@bluefish6
Copy link

Issue description:

When using Pytest with pytest-cov and coverage, some lines are marked as not covered.

Originally this issue was created in coverage repository: nedbat/coveragepy#605 (comment)

def test_literal_list():
    assert(
        [0,1,2] == [0,1,2]
    )

def test_foobar():
    assert(
        [0,1,2] == list(x for x in range(3))
    )

def test_foobar2():
    assert (
        [x for x in range(3)] == [0, 1, 2]
    )

def test_foobar2_oneline():
    assert ([x for x in range(3)] == [0, 1, 2])
py.test --cov=. --cov-report term-missing --cov-branch -s
================================== test session starts ==================================
platform linux -- Python 3.5.2, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: /home/.../coverage_test, inifile:
plugins: cov-2.5.1
collected 4 items                                                                       

test_foo.py ....

----------- coverage: platform linux, python 3.5.2-final-0 -----------
Name          Stmts   Miss Branch BrPart  Cover   Missing
---------------------------------------------------------
test_foo.py      12      0      6      2    89%   13->exit, 21->exit


=============================== 4 passed in 2.42 seconds ================================

After manually disabling AssertionRewritingHook (.../site-packages/_pytest/assertion/__init.__.py):

def install_importhook(config):
    """Try to install the rewrite hook, raise SystemError if it fails."""
    raise SystemError("rewrite not supported")

the result is as expected:

py.test --cov=. --cov-report term-missing --cov-branch -s
================================== test session starts ==================================
platform linux -- Python 3.5.2, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: /home/.../coverage_test, inifile:
plugins: cov-2.5.1
collected 4 items                                                                       

test_foo.py ....

----------- coverage: platform linux, python 3.5.2-final-0 -----------
Name          Stmts   Miss Branch BrPart  Cover   Missing
---------------------------------------------------------
test_foo.py      12      0      6      0   100%


=============================== 4 passed in 2.51 seconds ================================

So it seems that the AssertionRewritingHook changes somehow multiline asserts like:

    assert (
        [x for x in range(3)] == [0, 1, 2]
    )

Additional info

Pytest: 3.6.3
OS: Ubuntu 16.04

PIP list

Package        Version
-------------- -------
atomicwrites   1.1.5  
attrs          18.1.0 
coverage       4.5.1  
more-itertools 4.2.0  
pip            10.0.1 
pluggy         0.6.0  
py             1.5.4  
pytest         3.6.3  
pytest-cov     2.5.1  
setuptools     40.0.0 
six            1.11.0 
wheel          0.31.1
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #2131 (assertion rewrite confuses coverage), #1067 (Broken link), #668 (autouse fixtures break scope rules), #1690 (Appveyor is broken), and #2165 (addopts behavior with coverage flag).

@bluefish6
Copy link
Author

Seems like duplicate of #2131

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jul 17, 2018
@Zac-HD Zac-HD added the topic: rewrite related to the assertion rewrite mechanism label Oct 21, 2018
@Zac-HD
Copy link
Member

Zac-HD commented Oct 21, 2018

Via #2131 I think this is also a duplicate of nedbat/coveragepy#515

@Zac-HD Zac-HD closed this as completed Oct 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: rewrite related to the assertion rewrite mechanism type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

3 participants