@@ -246,6 +246,41 @@ def test_code_after_loop_execution(self, repl):
246246 repl .expect (r"-> 123" , timeout = 10 )
247247 repl .expect (">>>" , timeout = 10 )
248248
249+ def test_multiple_prints_in_loop (self , repl ):
250+ """Test that multiple print statements in a loop all produce output."""
251+ # Execute a for loop with multiple print statements
252+ repl .sendline ("for i in range(3):" )
253+ repl .expect (r"\.\.\." , timeout = 10 )
254+
255+ repl .sendline (" print(i)" )
256+ repl .expect (r"\.\.\." , timeout = 10 )
257+
258+ repl .sendline (" print('and')" )
259+ repl .expect (r"\.\.\." , timeout = 10 )
260+
261+ # Send empty line to finish the loop
262+ repl .sendline ("" )
263+
264+ # Should see output from BOTH print statements for each iteration
265+ repl .expect ("0" , timeout = 10 )
266+ repl .expect ("and" , timeout = 10 )
267+ repl .expect ("1" , timeout = 10 )
268+ repl .expect ("and" , timeout = 10 )
269+ repl .expect ("2" , timeout = 10 )
270+ repl .expect ("and" , timeout = 10 )
271+ repl .expect (">>>" , timeout = 10 )
272+
273+ # Now execute code after the loop - the loop should NOT re-execute
274+ repl .sendline ("99" )
275+ repl .expect (r"-> 99" , timeout = 10 )
276+
277+ # Get everything before the prompt to check no repeated output
278+ repl .expect (">>>" , timeout = 10 )
279+
280+ # Verify that we don't see the loop output repeated
281+ # (the 'before' buffer should only contain "-> 99" and not "0", "1", "2", "and")
282+ assert repl .before .count ("and" ) == 0 , "Loop output should not repeat"
283+
249284
250285@pytest .mark .slow
251286class TestREPLPersistence :
0 commit comments