File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -182,15 +182,20 @@ def test_python_version_file_adapt(content, expected):
182182
183183 We should convert them to the constraints that connect expects.
184184 """
185- with tempfile .NamedTemporaryFile (mode = "w+" ) as tmpfile :
185+ # delete=False is necessary on windows to reopen the file.
186+ # Otherwise it can't be opened again.
187+ # Ideally delete_on_close=False does what we need, but it's only >=3.12
188+ with tempfile .NamedTemporaryFile (mode = "w+" , delete = False ) as tmpfile :
186189 tmpfile .write (content )
187190 tmpfile .flush ()
188191
189- versionfile = pathlib .Path (tmpfile .name )
190-
191- if isinstance (expected , Exception ):
192- with pytest .raises (expected .__class__ ) as excinfo :
193- parse_pyversion_python_requires (versionfile )
194- assert str (excinfo .value ) == expected .args [0 ]
195- else :
196- assert parse_pyversion_python_requires (versionfile ) == expected
192+ try :
193+ versionfile = pathlib .Path (tmpfile .name )
194+ if isinstance (expected , Exception ):
195+ with pytest .raises (expected .__class__ ) as excinfo :
196+ parse_pyversion_python_requires (versionfile )
197+ assert str (excinfo .value ) == expected .args [0 ]
198+ else :
199+ assert parse_pyversion_python_requires (versionfile ) == expected
200+ finally :
201+ os .remove (tmpfile .name )
You can’t perform that action at this time.
0 commit comments