Skip to content

Commit 7044e92

Browse files
committed
Fixes project name clashes in restart tests
Introduces a worker suffix to project names in restart tests to avoid conflicts when running tests in parallel using xdist. This ensures that each worker has its own isolated project directory, preventing interference and ensuring accurate test results.
1 parent d164e2b commit 7044e92

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

functional/restart_test.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
from arc.main import ARC
1717

1818

19+
def _worker_suffix() -> str:
20+
"""Use the xdist worker id to isolate per-worker project directories."""
21+
worker = os.getenv('PYTEST_XDIST_WORKER')
22+
return f'_{worker}' if worker else ''
23+
24+
1925
class TestRestart(unittest.TestCase):
2026
"""
2127
Contains unit tests for restarting ARC.
@@ -36,7 +42,7 @@ def test_restart_thermo(self):
3642
"""
3743
restart_dir = os.path.join(ARC_PATH, 'arc', 'testing', 'restart', '1_restart_thermo')
3844
restart_path = os.path.join(restart_dir, 'restart.yml')
39-
project = 'arc_project_for_testing_delete_after_usage_restart_thermo'
45+
project = f'arc_project_for_testing_delete_after_usage_restart_thermo{_worker_suffix()}'
4046
project_directory = os.path.join(ARC_PATH, 'Projects', project)
4147
os.makedirs(os.path.dirname(project_directory), exist_ok=True)
4248
shutil.copytree(os.path.join(restart_dir, 'calcs'), os.path.join(project_directory, 'calcs', 'Species'), dirs_exist_ok=True)
@@ -55,7 +61,7 @@ def test_restart_thermo(self):
5561
break
5662
self.assertTrue(thermo_dft_ccsdtf12_bac)
5763

58-
with open(os.path.join(project_directory, 'arc_project_for_testing_delete_after_usage_restart_thermo.info'), 'r') as f:
64+
with open(os.path.join(project_directory, f'{project}.info'), 'r') as f:
5965
sts, n2h3, oet, lot, ap = False, False, False, False, False
6066
for line in f.readlines():
6167
if 'Considered the following species and TSs:' in line:
@@ -133,7 +139,7 @@ def test_restart_rate_1(self):
133139
"""Test restarting ARC and attaining a reaction rate coefficient"""
134140
restart_dir = os.path.join(ARC_PATH, 'arc', 'testing', 'restart', '2_restart_rate')
135141
restart_path = os.path.join(restart_dir, 'restart.yml')
136-
project = 'arc_project_for_testing_delete_after_usage_restart_rate_1'
142+
project = f'arc_project_for_testing_delete_after_usage_restart_rate_1{_worker_suffix()}'
137143
project_directory = os.path.join(ARC_PATH, 'Projects', project)
138144
os.makedirs(os.path.dirname(project_directory), exist_ok=True)
139145
shutil.copytree(os.path.join(restart_dir, 'calcs'), os.path.join(project_directory, 'calcs'), dirs_exist_ok=True)
@@ -154,7 +160,7 @@ def test_restart_rate_1(self):
154160

155161
def test_restart_rate_2(self):
156162
"""Test restarting ARC and attaining a reaction rate coefficient"""
157-
project = 'arc_project_for_testing_delete_after_usage_restart_rate_2'
163+
project = f'arc_project_for_testing_delete_after_usage_restart_rate_2{_worker_suffix()}'
158164
project_directory = os.path.join(ARC_PATH, 'Projects', project)
159165
base_path = os.path.join(ARC_PATH, 'arc', 'testing', 'restart', '5_TS1')
160166
restart_path = os.path.join(base_path, 'restart.yml')
@@ -183,7 +189,7 @@ def test_restart_bde (self):
183189
"""Test restarting ARC and attaining a BDE for anilino_radical."""
184190
restart_dir = os.path.join(ARC_PATH, 'arc', 'testing', 'restart', '3_restart_bde')
185191
restart_path = os.path.join(restart_dir, 'restart.yml')
186-
project = 'test_restart_bde'
192+
project = f'test_restart_bde{_worker_suffix()}'
187193
project_directory = os.path.join(ARC_PATH, 'Projects', project)
188194
os.makedirs(os.path.dirname(project_directory), exist_ok=True)
189195
shutil.copytree(os.path.join(restart_dir, 'calcs'), os.path.join(project_directory, 'calcs'), dirs_exist_ok=True)
@@ -192,7 +198,7 @@ def test_restart_bde (self):
192198
arc1 = ARC(**input_dict)
193199
arc1.execute()
194200

195-
report_path = os.path.join(ARC_PATH, 'Projects', 'test_restart_bde', 'output', 'BDE_report.txt')
201+
report_path = os.path.join(ARC_PATH, 'Projects', project, 'output', 'BDE_report.txt')
196202
with open(report_path, 'r') as f:
197203
lines = f.readlines()
198204
self.assertIn(' BDE report for anilino_radical:\n', lines)
@@ -218,10 +224,11 @@ def tearDownClass(cls):
218224
A function that is run ONCE after all unit tests in this class.
219225
Delete all project directories created during these unit tests
220226
"""
221-
projects = ['arc_project_for_testing_delete_after_usage_restart_thermo',
222-
'arc_project_for_testing_delete_after_usage_restart_rate_1',
223-
'arc_project_for_testing_delete_after_usage_restart_rate_2',
224-
'test_restart_bde',
227+
suffix = _worker_suffix()
228+
projects = [f'arc_project_for_testing_delete_after_usage_restart_thermo{suffix}',
229+
f'arc_project_for_testing_delete_after_usage_restart_rate_1{suffix}',
230+
f'arc_project_for_testing_delete_after_usage_restart_rate_2{suffix}',
231+
f'test_restart_bde{suffix}',
225232
]
226233
for project in projects:
227234
project_directory = os.path.join(ARC_PATH, 'Projects', project)

0 commit comments

Comments
 (0)