@@ -118,7 +118,7 @@ def test_setupcfg_python_requires(project_dir, expected):
118118@pytest .mark .parametrize (
119119 "project_dir, expected" ,
120120 [
121- (os .path .join (PROJECTS_DIRECTORY , "using_pyversion" ), ">=3.8, <3.12" ),
121+ (os .path .join (PROJECTS_DIRECTORY , "using_pyversion" ), ">=3.8,<3.12" ),
122122 ],
123123 ids = ["option-exists" ],
124124)
@@ -140,7 +140,7 @@ def test_detect_python_version_requirement():
140140 version requirement is used.
141141 """
142142 project_dir = os .path .join (PROJECTS_DIRECTORY , "allofthem" )
143- assert detect_python_version_requirement (project_dir ) == ">=3.8, <3.12"
143+ assert detect_python_version_requirement (project_dir ) == ">=3.8,<3.12"
144144
145145 assert detect_python_version_requirement (os .path .join (PROJECTS_DIRECTORY , "empty" )) is None
146146
@@ -182,15 +182,21 @@ 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 ()
188-
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
191+ tmpfile .close () # Also needed for windows to allow subsequent reading.
192+
193+ try :
194+ versionfile = pathlib .Path (tmpfile .name )
195+ if isinstance (expected , Exception ):
196+ with pytest .raises (expected .__class__ ) as excinfo :
197+ parse_pyversion_python_requires (versionfile )
198+ assert str (excinfo .value ) == expected .args [0 ]
199+ else :
200+ assert parse_pyversion_python_requires (versionfile ) == expected
201+ finally :
202+ os .remove (tmpfile .name )
0 commit comments