pytest: Assertions on nested comprehensions can give NameError

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  

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 16 (13 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve compiled the list of regressions in the original issue (#5062) to make sure we don’t miss any in the future. 👍

Hi @alimcmaster1,

Thanks for the offer, but I don’t think we should add specific tests for all in the assertion rewriter tests given that we don’t have any special handling for it anymore.

But we will definitely revisit all examples reported and include them in the test suite if/when we re-introduce all() unrolling in the assertion rewriter. 👍