Skip to content
Merged
Changes from 1 commit
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
Next Next commit
fix: race condition in OpenMLSplitTest when running tests in parallel
Use unique temp directories for each test instance to prevent
concurrent workers from interfering with shared pickle cache files.

Fixes #1641
  • Loading branch information
Alm0stSurely committed Feb 18, 2026
commit 0fec17c122f93ac9088f85c2b6bd9412ddd9df49
13 changes: 10 additions & 3 deletions tests/test_tasks/test_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import inspect
import os
import shutil
import tempfile
from pathlib import Path

import numpy as np
Expand All @@ -19,7 +21,7 @@ def setUp(self):
__file__ = inspect.getfile(OpenMLSplitTest)
self.directory = os.path.dirname(__file__)
# This is for dataset
self.arff_filepath = (
source_arff = (
Path(self.directory).parent
/ "files"
/ "org"
Expand All @@ -29,13 +31,18 @@ def setUp(self):
/ "1882"
/ "datasplits.arff"
)
# Use a unique temp directory for each test to avoid race conditions
# when running tests in parallel (see issue #1641)
self._temp_dir = tempfile.mkdtemp()
self.arff_filepath = Path(self._temp_dir) / "datasplits.arff"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mkdtemp is fine, but I'd prefer TemporaryDirectory since it's safer and reduces cleanup code.

Then in tearDown you can simply call self._temp_dir.cleanup()

shutil.copy(source_arff, self.arff_filepath)
self.pd_filename = self.arff_filepath.with_suffix(".pkl.py3")

def tearDown(self):
# Clean up the entire temp directory
try:
os.remove(self.pd_filename)
shutil.rmtree(self._temp_dir)
except (OSError, FileNotFoundError):
# Replaced bare except. Not sure why these exceptions are acceptable.
pass
Comment thread
fkiraly marked this conversation as resolved.

def test_eq(self):
Expand Down