Skip to content

Commit b00fbc2

Browse files
committed
ensure cleaning after tests
1 parent 422de2d commit b00fbc2

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

tests/code/test_pypeec.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@
2525
PATH_ROOT = os.path.dirname(__file__)
2626

2727

28+
def _create_temp_file():
29+
"""
30+
Get a temporary file.
31+
"""
32+
33+
(_, filename) = tempfile.mkstemp(suffix=".mpk")
34+
35+
return filename
36+
37+
38+
def _delete_temp_file(filename):
39+
"""
40+
Delete a temporary file.
41+
"""
42+
43+
try:
44+
os.remove(filename)
45+
except OSError:
46+
pass
47+
48+
2849
def _get_run_mesher(use_script, file_geometry, file_voxel):
2950
"""
3051
Run the mesher.
@@ -166,8 +187,8 @@ def run_workflow(name, use_script):
166187
file_tolerance = os.path.join(folder_examples, "config", "tolerance.yaml")
167188

168189
# get the temporary files
169-
(_, file_voxel) = tempfile.mkstemp(suffix=".mpk")
170-
(_, file_solution) = tempfile.mkstemp(suffix=".mpk")
190+
file_voxel = _create_temp_file()
191+
file_solution = _create_temp_file()
171192

172193
# run the workflow and load the results
173194
try:
@@ -181,8 +202,8 @@ def run_workflow(name, use_script):
181202
data_voxel = scisave.load_data(file_voxel)
182203
data_solution = scisave.load_data(file_solution)
183204
finally:
184-
# close the temporary files
185-
os.remove(file_voxel)
186-
os.remove(file_solution)
205+
# delete the temporary files
206+
_delete_temp_file(file_voxel)
207+
_delete_temp_file(file_solution)
187208

188209
return data_voxel, data_solution

0 commit comments

Comments
 (0)