Skip to content

Commit 51a9b1a

Browse files
committed
try to fix windows cleanup issue
1 parent ebf066b commit 51a9b1a

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

tests/embedder/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import platform
2+
3+
import pytest
4+
5+
6+
@pytest.fixture
7+
def on_windows() -> bool:
8+
return platform.system() == "Windows"

tests/embedder/test_dump_load.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from autointent.configs._transformers import EmbedderConfig
99

1010

11-
def test_load_from_disk():
11+
def test_load_from_disk(on_windows):
1212
model = SentenceTransformer("sergeyzh/rubert-tiny-turbo")
1313

14-
with tempfile.TemporaryDirectory() as tmp_dir:
14+
with tempfile.TemporaryDirectory(ignore_cleanup_errors=on_windows) as tmp_dir:
1515
model.save(str(Path(tmp_dir) / "weights"))
1616
embedder = Embedder(EmbedderConfig(model_name=str(Path(tmp_dir) / "weights")))
1717
predictions = embedder.embed(["hi!"])
@@ -22,7 +22,7 @@ def test_load_from_disk():
2222
np.testing.assert_almost_equal(predictions_after, predictions, decimal=4)
2323

2424

25-
def test_dump_load_cycle():
25+
def test_dump_load_cycle(on_windows):
2626
"""Test complete dump/load cycle preserves functionality."""
2727
original_config = EmbedderConfig(
2828
model_name="sergeyzh/rubert-tiny-turbo",
@@ -32,7 +32,7 @@ def test_dump_load_cycle():
3232
use_cache=False,
3333
)
3434

35-
with tempfile.TemporaryDirectory() as temp_dir:
35+
with tempfile.TemporaryDirectory(ignore_cleanup_errors=on_windows) as temp_dir:
3636
temp_path = Path(temp_dir)
3737

3838
# Create and test original embedder
@@ -56,15 +56,15 @@ def test_dump_load_cycle():
5656
assert embedder_loaded.config.similarity_fn_name == original_config.similarity_fn_name
5757

5858

59-
def test_load_with_config_override():
59+
def test_load_with_config_override(on_windows):
6060
"""Test loading with configuration override."""
6161
original_config = EmbedderConfig(
6262
model_name="sergeyzh/rubert-tiny-turbo",
6363
batch_size=8,
6464
use_cache=False,
6565
)
6666

67-
with tempfile.TemporaryDirectory() as temp_dir:
67+
with tempfile.TemporaryDirectory(ignore_cleanup_errors=on_windows) as temp_dir:
6868
temp_path = Path(temp_dir)
6969

7070
# Create and dump original

tests/embedder/test_fine_tuned_dump_load.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from autointent.context.data_handler import DataHandler
1010

1111

12-
def test_finetune_dump_load(dataset):
12+
def test_finetune_dump_load(dataset, on_windows):
1313
"""Test scenario: fine-tune -> dump -> load."""
1414
data_handler = DataHandler(dataset)
1515

@@ -24,7 +24,7 @@ def test_finetune_dump_load(dataset):
2424

2525
train_config = EmbedderFineTuningConfig(epoch_num=1, batch_size=4, early_stopping=False)
2626

27-
with tempfile.TemporaryDirectory() as temp_dir:
27+
with tempfile.TemporaryDirectory(ignore_cleanup_errors=on_windows) as temp_dir:
2828
temp_path = Path(temp_dir)
2929

3030
# Step 1: Fine-tune the embedder
@@ -64,7 +64,7 @@ def test_finetune_dump_load(dataset):
6464
)
6565

6666

67-
def test_dump_load_finetune(dataset):
67+
def test_dump_load_finetune(dataset, on_windows):
6868
"""Test scenario: dump -> load -> fine-tune."""
6969
data_handler = DataHandler(dataset)
7070

@@ -79,7 +79,7 @@ def test_dump_load_finetune(dataset):
7979

8080
train_config = EmbedderFineTuningConfig(epoch_num=1, batch_size=4, early_stopping=False)
8181

82-
with tempfile.TemporaryDirectory() as temp_dir:
82+
with tempfile.TemporaryDirectory(ignore_cleanup_errors=on_windows) as temp_dir:
8383
temp_path = Path(temp_dir)
8484

8585
# Step 1: Create and dump original embedder (not fine-tuned)
@@ -116,11 +116,11 @@ def test_dump_load_finetune(dataset):
116116
), "Embeddings should change after fine-tuning the loaded model"
117117

118118

119-
def test_load_from_disk_finetune_dump_load(dataset):
119+
def test_load_from_disk_finetune_dump_load(dataset, on_windows):
120120
"""Test scenario: load sentence transformer from disk -> fine-tune -> dump -> load."""
121121
data_handler = DataHandler(dataset)
122122

123-
with tempfile.TemporaryDirectory() as temp_dir:
123+
with tempfile.TemporaryDirectory(ignore_cleanup_errors=on_windows) as temp_dir:
124124
temp_path = Path(temp_dir)
125125

126126
# Step 1: Save a sentence transformer model to disk
@@ -173,7 +173,7 @@ def test_load_from_disk_finetune_dump_load(dataset):
173173
)
174174

175175

176-
def test_embeddings_consistency_across_workflows(dataset):
176+
def test_embeddings_consistency_across_workflows(dataset, on_windows):
177177
"""Test that different workflows produce consistent results when starting from same model."""
178178
data_handler = DataHandler(dataset)
179179

@@ -193,7 +193,7 @@ def test_embeddings_consistency_across_workflows(dataset):
193193
"labels": data_handler.train_labels(0)[:50],
194194
}
195195

196-
with tempfile.TemporaryDirectory() as temp_dir:
196+
with tempfile.TemporaryDirectory(ignore_cleanup_errors=on_windows) as temp_dir:
197197
temp_path = Path(temp_dir)
198198

199199
# Workflow 1: Direct fine-tune
@@ -217,7 +217,7 @@ def test_embeddings_consistency_across_workflows(dataset):
217217
)
218218

219219

220-
def test_multiple_dump_load_cycles_after_finetuning(dataset):
220+
def test_multiple_dump_load_cycles_after_finetuning(dataset, on_windows):
221221
"""Test that multiple dump/load cycles preserve fine-tuned model state."""
222222
data_handler = DataHandler(dataset)
223223

@@ -231,7 +231,7 @@ def test_multiple_dump_load_cycles_after_finetuning(dataset):
231231

232232
train_config = EmbedderFineTuningConfig(epoch_num=1, batch_size=4, early_stopping=False)
233233

234-
with tempfile.TemporaryDirectory() as temp_dir:
234+
with tempfile.TemporaryDirectory(ignore_cleanup_errors=on_windows) as temp_dir:
235235
temp_path = Path(temp_dir)
236236

237237
# Fine-tune original embedder

0 commit comments

Comments
 (0)