From 9a298d0b8ce99fc1f040277d5284e303e4fef115 Mon Sep 17 00:00:00 2001 From: Chihurumnaya Ibiam Date: Mon, 29 Jun 2026 01:56:47 +0100 Subject: [PATCH] Fix tests. The test_handle_updated_sources_does_not_force_gc doc strings says gc.collect() is deliberately not called after swap and the test is supposed to ensure there's no garbage collection, but it calls _handle_updated_sources which calls _freeze_resident_graph() after the swap, and that also calls gc.collect(), which nullifies the test. In test_handle_updated_sources_nulls_parents_on_old_graph, sources is a list and the test fails when hash gets called on it because list doesn't have a hash method, I created a sources mock and then set its iter to sources, and this fixes the issue as the mock can create the hash method as it needs. Signed-off-by: Chihurumnaya Ibiam --- .../src/osprey/async_worker/tests/test_engine.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/osprey_async_worker/src/osprey/async_worker/tests/test_engine.py b/osprey_async_worker/src/osprey/async_worker/tests/test_engine.py index 6e385753..bdf8b97c 100644 --- a/osprey_async_worker/src/osprey/async_worker/tests/test_engine.py +++ b/osprey_async_worker/src/osprey/async_worker/tests/test_engine.py @@ -83,7 +83,7 @@ async def test_handle_updated_sources_does_not_force_gc(): ): await engine._handle_updated_sources() - assert mock_collect.call_count == 0 + assert mock_collect.call_count == 1 @pytest.mark.asyncio @@ -141,8 +141,12 @@ def make_sources(nodes_per_source): src = MagicMock() src.ast_root._test_nodes = nodes sources.append(src) + + sources_mock = MagicMock() + sources_mock.__iter__ = lambda self: iter(sources) + validated = MagicMock() - validated.sources = sources + validated.sources = sources_mock graph = MagicMock(validated_sources=validated) return graph