π OpenHands: AI-Driven Development
Fix flaky TestLocalFileStore tests (#8569)
Graham Neubig2dc7b37fe8d2
diff --git a/tests/unit/test_storage.py b/tests/unit/test_storage.pyindex 7fae5f8c08..a78c12df98 100644--- a/tests/unit/test_storage.py+++ b/tests/unit/test_storage.py@@ -1,7 +1,8 @@from __future__ import annotations-import os+import loggingimport shutil+import tempfilefrom abc import ABCfrom dataclasses import dataclass, fieldfrom io import BytesIO, StringIO@@ -108,11 +109,18 @@ class _StorageTest(ABC):class TestLocalFileStore(TestCase, _StorageTest):def setUp(self):- os.makedirs('./_test_files_tmp', exist_ok=True)- self.store = LocalFileStore('./_test_files_tmp')+ # Create a unique temporary directory for each test instance+ self.temp_dir = tempfile.mkdtemp(prefix='openhands_test_')+ self.store = LocalFileStore(self.temp_dir)def tearDown(self):- shutil.rmtree('./_test_files_tmp')+ try:+ # Use ignore_errors=True to avoid failures if directory is not empty+ shutil.rmtree(self.temp_dir, ignore_errors=True)+ except Exception as e:+ logging.warning(+ f'Failed to remove temporary directory {self.temp_dir}: {e}'+ )class TestInMemoryFileStore(TestCase, _StorageTest):