Skip to content

Commit e387c66

Browse files
authored
Resolve race condition in data tests by using dynamic temporary directories (#1044)
1 parent a200b0b commit e387c66

15 files changed

+36
-22
lines changed

tests/data_tests/Operators/test_agentic_rag_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import shutil
4+
import tempfile
45
from lazyllm import config
56
from lazyllm.tools.data import agenticrag
67

@@ -48,7 +49,7 @@ def share(self, prompt=None, format=None, stream=None, history=None):
4849

4950
class TestAgenticRAGOperators:
5051
def setup_method(self):
51-
self.root_dir = './test_data_op'
52+
self.root_dir = tempfile.mkdtemp()
5253
self.keep_dir = config['data_process_path']
5354
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
5455
config.refresh()

tests/data_tests/Operators/test_basic_ops.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import shutil
3+
import tempfile
34

45
from lazyllm import config, LOG
56
from lazyllm.tools.data import refine, chunker, filter
@@ -27,7 +28,7 @@ def start(self):
2728
class TestRefineOperators:
2829

2930
def setup_method(self):
30-
self.root_dir = './test_data_op'
31+
self.root_dir = tempfile.mkdtemp()
3132
self.keep_dir = config['data_process_path']
3233
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
3334
config.refresh()
@@ -99,7 +100,7 @@ def test_refine_chained_operations(self):
99100
class TestChunkerOperators:
100101

101102
def setup_method(self):
102-
self.root_dir = './test_data_op'
103+
self.root_dir = tempfile.mkdtemp()
103104
self.keep_dir = config['data_process_path']
104105
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
105106
config.refresh()
@@ -131,7 +132,7 @@ def test_token_chunker(self):
131132
class TestFilterOperators:
132133

133134
def setup_method(self):
134-
self.root_dir = './test_data_op'
135+
self.root_dir = tempfile.mkdtemp()
135136
self.keep_dir = config['data_process_path']
136137
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
137138
config.refresh()

tests/data_tests/Operators/test_codegen_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import shutil
33
import json
4+
import tempfile
45
from lazyllm import config
56
from lazyllm.tools.data.operators import codegen_ops
67

@@ -32,7 +33,7 @@ def __call__(self, *args, **kwargs):
3233
class TestCodeGenOps:
3334

3435
def setup_method(self):
35-
self.root_dir = './test_codegen_ops'
36+
self.root_dir = tempfile.mkdtemp()
3637
self.keep_dir = config['data_process_path']
3738
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
3839
config.refresh()

tests/data_tests/Operators/test_demo_ops.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
import random
66
import json
7+
import tempfile
78
from lazyllm import config, LOG
89
from lazyllm.tools.data import data_register, demo1, demo2, llm_json_base
910

@@ -30,7 +31,7 @@ def start(self):
3031
class TestDataDemoOperators:
3132

3233
def setup_method(self):
33-
self.root_dir = './test_data_op'
34+
self.root_dir = tempfile.mkdtemp()
3435
self.keep_dir = config['data_process_path']
3536
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
3637
config.refresh()
@@ -168,7 +169,7 @@ def dummy_llm_op(data, input_key='text', output_key='llm_output'):
168169
class TestDataLLMDemoOperators:
169170

170171
def setup_method(self):
171-
self.root_dir = './test_data_op'
172+
self.root_dir = tempfile.mkdtemp()
172173
self.keep_dir = config['data_process_path']
173174
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
174175
config.refresh()

tests/data_tests/Operators/test_embedding_synthesis_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import shutil
4+
import tempfile
45
import numpy as np
56
from lazyllm import config
67
from lazyllm.tools.data import embedding
@@ -64,7 +65,7 @@ def __call__(self, texts):
6465

6566
class TestEmbeddingSynthesisOperators:
6667
def setup_method(self):
67-
self.root_dir = './test_data_op'
68+
self.root_dir = tempfile.mkdtemp()
6869
self.keep_dir = config['data_process_path']
6970
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
7071
config.refresh()

tests/data_tests/Operators/test_generate_cot_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import shutil
3+
import tempfile
34

45
from lazyllm import config
56
from lazyllm.tools.data import genCot
@@ -27,7 +28,7 @@ def start(self):
2728
class TestGenCotOperators:
2829

2930
def setup_method(self):
30-
self.root_dir = './test_data_op'
31+
self.root_dir = tempfile.mkdtemp()
3132
self.keep_dir = config['data_process_path']
3233
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
3334
config.refresh()

tests/data_tests/Operators/test_knowledge_cleaning_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def share(self, prompt=None, format=None, stream=None, history=None):
4747

4848
class TestKnowledgeCleaningOperators:
4949
def setup_method(self):
50-
self.root_dir = './test_kbc_op'
50+
self.root_dir = tempfile.mkdtemp()
5151
self.keep_dir = config['data_process_path']
5252
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
5353
config.refresh()

tests/data_tests/Operators/test_math_qa_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import shutil
3+
import tempfile
34

45
from lazyllm import config
56
from lazyllm.tools.data import MathQA
@@ -27,7 +28,7 @@ def start(self):
2728
class TestMathQAOperators:
2829

2930
def setup_method(self):
30-
self.root_dir = './test_data_op'
31+
self.root_dir = tempfile.mkdtemp()
3132
self.keep_dir = config['data_process_path']
3233
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
3334
config.refresh()

tests/data_tests/Operators/test_preference_ops.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
22
import shutil
3+
import tempfile
4+
35
from lazyllm import config
46
from lazyllm.tools.data.operators import preference_ops
5-
import pytest # noqa: F401
67

78
class TestPreferenceOperators:
89
class MockModel:
@@ -19,7 +20,7 @@ def __call__(self, x, **kwargs):
1920
return self.return_val
2021

2122
def setup_method(self):
22-
self.root_dir = './test_preference_op'
23+
self.root_dir = tempfile.mkdtemp()
2324
self.keep_dir = config['data_process_path']
2425
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
2526
config.refresh()

tests/data_tests/Operators/test_pretrain_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def start(self):
3131
class TestPretrainOperators:
3232

3333
def setup_method(self):
34-
self.root_dir = './test_data_op'
34+
self.root_dir = tempfile.mkdtemp()
3535
self.keep_dir = config['data_process_path']
3636
os.environ['LAZYLLM_DATA_PROCESS_PATH'] = self.root_dir
3737
config.refresh()

0 commit comments

Comments
 (0)