1616from arc .main import ARC
1717
1818
19+ def _project_name (base : str ) -> str :
20+ """Return a per-xdist-worker project name to avoid parallel cleanup collisions."""
21+ worker_id = os .environ .get ('PYTEST_XDIST_WORKER' )
22+ if worker_id :
23+ return f'{ base } _{ worker_id } '
24+ return base
25+
26+
1927class TestRestart (unittest .TestCase ):
2028 """
2129 Contains unit tests for restarting ARC.
@@ -36,7 +44,7 @@ def test_restart_thermo(self):
3644 """
3745 restart_dir = os .path .join (ARC_PATH , 'arc' , 'testing' , 'restart' , '1_restart_thermo' )
3846 restart_path = os .path .join (restart_dir , 'restart.yml' )
39- project = 'arc_project_for_testing_delete_after_usage_restart_thermo'
47+ project = _project_name ( 'arc_project_for_testing_delete_after_usage_restart_thermo' )
4048 project_directory = os .path .join (ARC_PATH , 'Projects' , project )
4149 os .makedirs (os .path .dirname (project_directory ), exist_ok = True )
4250 shutil .copytree (os .path .join (restart_dir , 'calcs' ), os .path .join (project_directory , 'calcs' , 'Species' ), dirs_exist_ok = True )
@@ -55,7 +63,7 @@ def test_restart_thermo(self):
5563 break
5664 self .assertTrue (thermo_dft_ccsdtf12_bac )
5765
58- with open (os .path .join (project_directory , 'arc_project_for_testing_delete_after_usage_restart_thermo .info' ), 'r' ) as f :
66+ with open (os .path .join (project_directory , f' { project } .info' ), 'r' ) as f :
5967 sts , n2h3 , oet , lot , ap = False , False , False , False , False
6068 for line in f .readlines ():
6169 if 'Considered the following species and TSs:' in line :
@@ -66,7 +74,7 @@ def test_restart_thermo(self):
6674 oet = True
6775 elif 'Levels of theory used:' in line :
6876 lot = True
69- elif 'ARC project arc_project_for_testing_delete_after_usage_restart_thermo ' in line :
77+ elif f 'ARC project { project } ' in line :
7078 ap = True
7179 self .assertTrue (sts )
7280 self .assertTrue (n2h3 )
@@ -133,7 +141,7 @@ def test_restart_rate_1(self):
133141 """Test restarting ARC and attaining a reaction rate coefficient"""
134142 restart_dir = os .path .join (ARC_PATH , 'arc' , 'testing' , 'restart' , '2_restart_rate' )
135143 restart_path = os .path .join (restart_dir , 'restart.yml' )
136- project = 'arc_project_for_testing_delete_after_usage_restart_rate_1'
144+ project = _project_name ( 'arc_project_for_testing_delete_after_usage_restart_rate_1' )
137145 project_directory = os .path .join (ARC_PATH , 'Projects' , project )
138146 os .makedirs (os .path .dirname (project_directory ), exist_ok = True )
139147 shutil .copytree (os .path .join (restart_dir , 'calcs' ), os .path .join (project_directory , 'calcs' ), dirs_exist_ok = True )
@@ -154,7 +162,7 @@ def test_restart_rate_1(self):
154162
155163 def test_restart_rate_2 (self ):
156164 """Test restarting ARC and attaining a reaction rate coefficient"""
157- project = 'arc_project_for_testing_delete_after_usage_restart_rate_2'
165+ project = _project_name ( 'arc_project_for_testing_delete_after_usage_restart_rate_2' )
158166 project_directory = os .path .join (ARC_PATH , 'Projects' , project )
159167 base_path = os .path .join (ARC_PATH , 'arc' , 'testing' , 'restart' , '5_TS1' )
160168 restart_path = os .path .join (base_path , 'restart.yml' )
@@ -183,7 +191,7 @@ def test_restart_bde (self):
183191 """Test restarting ARC and attaining a BDE for anilino_radical."""
184192 restart_dir = os .path .join (ARC_PATH , 'arc' , 'testing' , 'restart' , '3_restart_bde' )
185193 restart_path = os .path .join (restart_dir , 'restart.yml' )
186- project = 'test_restart_bde'
194+ project = _project_name ( 'test_restart_bde' )
187195 project_directory = os .path .join (ARC_PATH , 'Projects' , project )
188196 os .makedirs (os .path .dirname (project_directory ), exist_ok = True )
189197 shutil .copytree (os .path .join (restart_dir , 'calcs' ), os .path .join (project_directory , 'calcs' ), dirs_exist_ok = True )
@@ -192,7 +200,7 @@ def test_restart_bde (self):
192200 arc1 = ARC (** input_dict )
193201 arc1 .execute ()
194202
195- report_path = os .path .join (ARC_PATH , 'Projects' , 'test_restart_bde' , 'output' , 'BDE_report.txt' )
203+ report_path = os .path .join (ARC_PATH , 'Projects' , project , 'output' , 'BDE_report.txt' )
196204 with open (report_path , 'r' ) as f :
197205 lines = f .readlines ()
198206 self .assertIn (' BDE report for anilino_radical:\n ' , lines )
@@ -218,10 +226,10 @@ def tearDownClass(cls):
218226 A function that is run ONCE after all unit tests in this class.
219227 Delete all project directories created during these unit tests
220228 """
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' ,
229+ projects = [_project_name ( 'arc_project_for_testing_delete_after_usage_restart_thermo' ) ,
230+ _project_name ( 'arc_project_for_testing_delete_after_usage_restart_rate_1' ) ,
231+ _project_name ( 'arc_project_for_testing_delete_after_usage_restart_rate_2' ) ,
232+ _project_name ( 'test_restart_bde' ) ,
225233 ]
226234 for project in projects :
227235 project_directory = os .path .join (ARC_PATH , 'Projects' , project )
0 commit comments