diff --git a/tests/conftest.py b/tests/conftest.py index 3c02d8d18..d3be0ce86 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import asyncio +import gc import multiprocessing.context import os import sys @@ -58,6 +59,12 @@ def pytest_runtest_setup(item): # type: ignore[reportMissingParameterType] print() +def pytest_collection_finish() -> None: + # Freeze the import-time heap once so full GC passes only cover test allocations + gc.collect() + gc.freeze() + + def pytest_addoption(parser): # type: ignore[reportMissingParameterType] parser.addoption( "-E", diff --git a/tests/contrib/langgraph/test_replay.py b/tests/contrib/langgraph/test_replay.py index f5d1a8e92..3c8880093 100644 --- a/tests/contrib/langgraph/test_replay.py +++ b/tests/contrib/langgraph/test_replay.py @@ -1,4 +1,5 @@ import sys +import warnings from datetime import timedelta from uuid import uuid4 @@ -52,10 +53,21 @@ async def test_replay(client: Client): ) await handle.result() - await Replayer( - workflows=[TwoNodesWorkflow], - plugins=[plugin], - ).replay_workflow(await handle.fetch_history()) + with warnings.catch_warnings(record=True) as recorder: + warnings.filterwarnings( + "always", message=r"Module .* was imported after initial workflow load" + ) + await Replayer( + workflows=[TwoNodesWorkflow], + plugins=[plugin], + ).replay_workflow(await handle.fetch_history()) + + # Sandbox imports during an activation count toward the deadlock timeout + assert not [ + str(w.message) + for w in recorder + if "was imported after initial workflow load" in str(w.message) + ] @pytest.mark.skipif(