@@ -178,19 +178,27 @@ def test_compile_with_symlink(run_command, data_dir):
178
178
179
179
# create a symlink to some external file and move the main .ino
180
180
# contents into that to check that the symlink is actually compiled
181
- with tempfile .NamedTemporaryFile () as external :
182
- os .symlink (external .name , symlink_file )
183
-
184
- with open (main_file , mode = "rb+" ) as main :
185
- external .write (main .read ())
186
- external .flush ()
187
- main .truncate (0 )
188
- main .flush ()
189
-
190
- # Build sketch for arduino:avr:uno
191
- result = run_command (["compile" , "-b" , fqbn , sketch_path ])
192
- assert result .stderr == ""
193
- assert result .ok
181
+ with tempfile .NamedTemporaryFile (delete = False ) as external :
182
+ try :
183
+ os .symlink (external .name , symlink_file )
184
+
185
+ with open (main_file , mode = "rb+" ) as main :
186
+ external .write (main .read ())
187
+ external .flush ()
188
+ main .truncate (0 )
189
+ main .flush ()
190
+
191
+ # Close to allow re-opening the file on Windows
192
+ # See https://bugs.python.org/issue14243
193
+ external .close ()
194
+
195
+ # Build sketch for arduino:avr:uno
196
+ result = run_command (["compile" , "-b" , fqbn , sketch_path ])
197
+ assert result .stderr == ""
198
+ assert result .ok
199
+ finally :
200
+ # Explicit cleanup needed because the file is closed above
201
+ os .unlink (external .name )
194
202
195
203
def test_broken_symlink (sketch_name , link_name , target_name , expect_error ):
196
204
sketch_path = os .path .join (data_dir , sketch_name )
0 commit comments