Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import gc
import glob
import random
from unittest.mock import patch

import dask
import pandas as pd
from npy_append_array import NpyAppendArray

from merlin.core.compat import cudf
from merlin.core.compat import numpy as np
from merlin.dataloader.loader_base import LoaderBase

if cudf:
try:
Expand Down Expand Up @@ -241,3 +243,17 @@ def np_embeddings_from_pq(rev_embeddings_from_dataframe, tmpdir_factory):
paths, embeddings_file, lookup_ids_file
)
return npy_filename, lookup_filename


@pytest.fixture(scope="function", autouse=True)
def cleanup_dataloader():
"""After each test runs. Call .stop() on any dataloaders created during the test.
The avoids issues with background threads hanging around and interfering with subsequent tests.
This happens when a dataloader is partially consumed (not all batches are iterated through).
"""
with patch.object(
LoaderBase, "__iter__", side_effect=LoaderBase.__iter__, autospec=True
) as patched:
yield
for call in patched.call_args_list:
call.args[0].stop()