Skip to content

Commit 0422fc1

Browse files
authored
[Testing] Reduce error verbosity of cleanup (#1365)
## Purpose ## * When tests fail, they often show the error that occurs during cleanup, rather than the error that caused the tests to fail ``` ERROR tests/llmcompressor/transformers/obcq/test_consecutive_runs.py::TestConsecutiveRunsSmall_0_commit::test_consecutive_runs_small - FileNotFoundError: [Errno 2] No such file or directory: './oneshot_output' ``` ## Changes ## * Check if a directory exists before attempting to delete it during cleanup Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
1 parent 9aedc8b commit 0422fc1

18 files changed

+60
-25
lines changed

tests/e2e/vLLM/test_vllm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_vllm(self, test_data_file: str):
170170
self.tear_down()
171171

172172
def tear_down(self):
173-
if self.save_dir is not None:
173+
if self.save_dir is not None and os.path.isdir(self.save_dir):
174174
shutil.rmtree(self.save_dir)
175175

176176
timer = get_singleton_manager()

tests/llmcompressor/transformers/compression/test_decompress.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import copy
2+
import os
23
import shutil
34
import tempfile
45
import unittest
@@ -128,7 +129,8 @@ def test_hf_quantizer_decompress_match_manual_decompress(self):
128129

129130
@classmethod
130131
def tearDownClass(self):
131-
shutil.rmtree(self.test_dir)
132+
if os.path.isdir(self.test_dir):
133+
shutil.rmtree(self.test_dir)
132134
del self.dense_model
133135
del self.decompressed_model_hf_quantizer
134136
del self.decompressed_model_manual

tests/llmcompressor/transformers/compression/test_quantization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def setUpClass(cls):
4949

5050
@classmethod
5151
def tearDownClass(cls):
52-
shutil.rmtree(cls.test_dir)
52+
if os.path.isdir(cls.test_dir):
53+
shutil.rmtree(cls.test_dir)
5354
del cls.model
5455
torch.cuda.empty_cache()
5556

tests/llmcompressor/transformers/compression/test_run_compressed.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import shutil
23
import tempfile
34
import unittest
@@ -82,7 +83,8 @@ def test_compressed_matches_decompressed(self):
8283

8384
@classmethod
8485
def tearDownClass(cls):
85-
shutil.rmtree(cls.test_dir)
86+
if os.path.isdir(cls.test_dir):
87+
shutil.rmtree(cls.test_dir)
8688
del cls.decompressed_model
8789
del cls.uncompressed_model
8890
torch.cuda.empty_cache()
@@ -167,7 +169,8 @@ def test_compressed_matches_decompressed__hf_quantizer(self):
167169

168170
@classmethod
169171
def tearDownClass(cls):
170-
shutil.rmtree(cls.test_dir)
172+
if os.path.isdir(cls.test_dir):
173+
shutil.rmtree(cls.test_dir)
171174
del cls.decompressed_model
172175
del cls.compressed_model
173176
torch.cuda.empty_cache()

tests/llmcompressor/transformers/finetune/test_finetune_no_recipe_custom_dataset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def create_mock_file(self, extension, content, path, filename):
107107
return mock_filepath # Return the file path
108108

109109
def tearDown(self):
110-
shutil.rmtree(self.output)
110+
if os.path.isdir(self.output):
111+
shutil.rmtree(self.output)
111112

112113

113114
@pytest.mark.integration

tests/llmcompressor/transformers/finetune/test_finetune_oneshot_with_modifier.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import shutil
23
import unittest
34
from pathlib import Path
@@ -46,4 +47,5 @@ def test_oneshot_with_modifier_object(self):
4647
)
4748

4849
def tearDown(self):
49-
shutil.rmtree(self.output)
50+
if os.path.isdir(self.output):
51+
shutil.rmtree(self.output)

tests/llmcompressor/transformers/finetune/test_finetune_without_recipe.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import shutil
23
import unittest
34

@@ -41,4 +42,5 @@ def test_finetune_without_recipe(self):
4142
)
4243

4344
def tearDown(self):
44-
shutil.rmtree(self.output)
45+
if os.path.isdir(self.output):
46+
shutil.rmtree(self.output)

tests/llmcompressor/transformers/finetune/test_oneshot_and_finetune.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def _test_oneshot_and_finetune(self):
7575
def tearDown(self):
7676
# TODO: we get really nice stats from finetune that we should log
7777
# stored in results.json
78-
shutil.rmtree(self.output)
78+
if os.path.isdir(self.output):
79+
shutil.rmtree(self.output)
7980

8081

8182
@pytest.mark.integration

tests/llmcompressor/transformers/finetune/test_oneshot_and_finetune_with_tokenizer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import shutil
23
import unittest
34

@@ -78,4 +79,5 @@ def test_oneshot_and_finetune_with_tokenizer(self):
7879
print(tokenizer.decode(output[0]))
7980

8081
def tearDown(self):
81-
shutil.rmtree(self.output)
82+
if os.path.isdir(self.output):
83+
shutil.rmtree(self.output)

tests/llmcompressor/transformers/finetune/test_oneshot_then_finetune.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import shutil
23
import unittest
34
from pathlib import Path
@@ -175,4 +176,5 @@ def test_oneshot_quantization_then_finetune(self):
175176
)
176177

177178
def tearDown(self):
178-
shutil.rmtree(self.output)
179+
if os.path.isdir(self.output):
180+
shutil.rmtree(self.output)

0 commit comments

Comments
 (0)