File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -132,12 +132,33 @@ def reset_in_fabric_backward():
132132@pytest .fixture
133133def reset_deterministic_algorithm ():
134134 """Ensures that torch determinism settings are reset before the next test runs."""
135- os .environ ["PL_FORCE_DETERMINISTIC_PORTS" ] = "1"
136135 yield
137136 os .environ .pop ("CUBLAS_WORKSPACE_CONFIG" , None )
138137 torch .use_deterministic_algorithms (False )
139138
140139
140+ @pytest .fixture (autouse = True )
141+ def cleanup_lightning_ports ():
142+ """Delete Lightning deterministic port files after all tests."""
143+ from lightning .fabric .plugins .environments .lightning import LOCK_FILE
144+
145+ # Ensure deterministic ports in tests
146+ os .environ ["PL_FORCE_DETERMINISTIC_PORTS" ] = "1"
147+
148+ yield
149+
150+ files_to_remove = [
151+ LOCK_FILE , # the port storage file
152+ LOCK_FILE + ".lock" , # the filelock lock file
153+ ]
154+ for f in files_to_remove :
155+ try :
156+ if os .path .exists (f ):
157+ os .remove (f )
158+ except Exception as e :
159+ print (f"Warning: failed to remove { f } : { e } " )
160+
161+
141162@pytest .fixture
142163def reset_cudnn_benchmark ():
143164 """Ensures that the `torch.backends.cudnn.benchmark` setting gets reset before the next test runs."""
Original file line number Diff line number Diff line change @@ -135,11 +135,32 @@ def teardown_process_group():
135135@pytest .fixture (autouse = True )
136136def reset_deterministic_algorithm ():
137137 """Ensures that torch determinism settings are reset before the next test runs."""
138- os .environ ["PL_FORCE_DETERMINISTIC_PORTS" ] = "1"
139138 yield
140139 torch .use_deterministic_algorithms (False )
141140
142141
142+ @pytest .fixture (autouse = True )
143+ def cleanup_lightning_ports ():
144+ """Delete Lightning deterministic port files after all tests."""
145+ from lightning .fabric .plugins .environments .lightning import LOCK_FILE
146+
147+ # Ensure deterministic ports in tests
148+ os .environ ["PL_FORCE_DETERMINISTIC_PORTS" ] = "1"
149+
150+ yield
151+
152+ files_to_remove = [
153+ LOCK_FILE , # the port storage file
154+ LOCK_FILE + ".lock" , # the filelock lock file
155+ ]
156+ for f in files_to_remove :
157+ try :
158+ if os .path .exists (f ):
159+ os .remove (f )
160+ except Exception as e :
161+ print (f"Warning: failed to remove { f } : { e } " )
162+
163+
143164@pytest .fixture (autouse = True )
144165def thread_police_duuu_daaa_duuu_daaa ():
145166 """Attempts to stop left-over threads to avoid test interactions."""
You can’t perform that action at this time.
0 commit comments