Skip to content

Commit b180c33

Browse files
siwachabhiAbhimanyu Siwach
andauthored
fix: Use itertools.cycle for time.time() mock to fix Python 3.12 compatibility (#327)
The test was failing on Python 3.12 with StopIteration when the side_effect list ran out of values. Using itertools.cycle provides unlimited values for the mock, ensuring compatibility across all Python versions. Co-authored-by: Abhimanyu Siwach <siwabhi@amazon.com>
1 parent 00778cd commit b180c33

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tests/operations/memory/test_manager.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,10 +1591,11 @@ def test_wait_for_memory_active_timeout_with_strategies():
15911591
}
15921592
}
15931593

1594-
# Mock time to simulate timeout - provide enough values for all time.time() calls
1595-
# The method calls: start_time, while condition check, elapsed calc,
1596-
# while condition check (timeout), elapsed calc
1597-
with patch("time.time", side_effect=[0, 0, 0, 61, 61]):
1594+
# Mock time to simulate timeout
1595+
# Use itertools.cycle to provide unlimited values for Python 3.12 compatibility
1596+
from itertools import cycle
1597+
1598+
with patch("time.time", side_effect=cycle([0, 0, 0, 61, 61, 61, 61, 61])):
15981599
with patch("time.sleep"):
15991600
try:
16001601
manager._wait_for_memory_active("mem-123", max_wait=60, poll_interval=5)

0 commit comments

Comments
 (0)