@@ -671,6 +671,53 @@ def __repr__(self):
671671 assert "UnicodeDecodeError" not in msg
672672 assert "UnicodeEncodeError" not in msg
673673
674+ def test_generator (self , testdir ):
675+ testdir .makepyfile (
676+ """
677+ def check_even(num):
678+ if num % 2 == 0:
679+ return True
680+ return False
681+
682+ def test_generator():
683+ odd_list = list(range(1,9,2))
684+ assert all(check_even(num) for num in odd_list)"""
685+ )
686+ result = testdir .runpytest ()
687+ result .stdout .fnmatch_lines (["*assert False*" , "*where False = check_even(1)*" ])
688+
689+ def test_list_comprehension (self , testdir ):
690+ testdir .makepyfile (
691+ """
692+ def check_even(num):
693+ if num % 2 == 0:
694+ return True
695+ return False
696+
697+ def test_list_comprehension():
698+ odd_list = list(range(1,9,2))
699+ assert all([check_even(num) for num in odd_list])"""
700+ )
701+ result = testdir .runpytest ()
702+ result .stdout .fnmatch_lines (["*assert False*" , "*where False = check_even(1)*" ])
703+
704+ def test_for_loop (self , testdir ):
705+ testdir .makepyfile (
706+ """
707+ def check_even(num):
708+ if num % 2 == 0:
709+ return True
710+ return False
711+
712+ def test_for_loop():
713+ odd_list = list(range(1,9,2))
714+ for num in odd_list:
715+ assert check_even(num)
716+ """
717+ )
718+ result = testdir .runpytest ()
719+ result .stdout .fnmatch_lines (["*assert False*" , "*where False = check_even(1)*" ])
720+
674721
675722class TestRewriteOnImport (object ):
676723 def test_pycache_is_a_file (self , testdir ):
0 commit comments