File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 2323import subprocess
2424import time
2525from pathlib import Path
26+ from unittest .mock import patch
2627
2728import dask
2829import pandas as pd
@@ -371,3 +372,19 @@ def devices(request):
371372@pytest .fixture
372373def report (request ):
373374 return request .config .getoption ("--report" )
375+
376+
377+ @pytest .fixture (scope = "function" , autouse = True )
378+ def cleanup_dataloader ():
379+ """After each test runs. Call .stop() on any dataloaders created during the test.
380+ The avoids issues with background threads hanging around and interfering with subsequent tests.
381+ This happens when a dataloader is partially consumed (not all batches are iterated through).
382+ """
383+ from merlin .dataloader .loader_base import LoaderBase
384+
385+ with patch .object (
386+ LoaderBase , "__iter__" , side_effect = LoaderBase .__iter__ , autospec = True
387+ ) as patched :
388+ yield
389+ for call in patched .call_args_list :
390+ call .args [0 ].stop ()
You can’t perform that action at this time.
0 commit comments