Skip to content

Assertions on nested comprehensions can give NameError #5370

@RacingTadpole

Description

@RacingTadpole

This test:

def test_nested_comprehension():
    s = [[True, True], [True, True]]
    assert all(e for row in s for e in row)

works fine in pytest 4.4.1 and 4.5.0. In pytest 4.6.1 it produces a NameError:

$ pytest
===================================================== test session starts =====================================================
platform darwin -- Python 3.7.3, pytest-4.6.1, py-1.8.0, pluggy-0.12.0
collected 1 item                                                                                                              

test_it.py F                                                                                                            [100%]

========================================================== FAILURES ===========================================================
__________________________________________________ test_nested_comprehension __________________________________________________

    def test_nested_comprehension():
        s = [[True, True], [True, True]]
>       assert all(e for row in s for e in row)
E       NameError: name 'e' is not defined

test_it.py:3: NameError
================================================== 1 failed in 0.06 seconds ===================================================

Pip list gives:

$ pip list
Package            Version
------------------ -------
atomicwrites       1.3.0  
attrs              19.1.0 
importlib-metadata 0.17   
more-itertools     7.0.0  
packaging          19.0   
pip                19.1.1 
pluggy             0.12.0 
py                 1.8.0  
pyparsing          2.4.0  
pytest             4.6.1  
setuptools         41.0.1 
six                1.12.0 
wcwidth            0.1.7  
wheel              0.33.4 
zipp               0.5.1  

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions