@@ -118,7 +118,7 @@ def test_setupcfg_python_requires(project_dir, expected):
118
118
@pytest .mark .parametrize (
119
119
"project_dir, expected" ,
120
120
[
121
- (os .path .join (PROJECTS_DIRECTORY , "using_pyversion" ), ">=3.8, <3.12" ),
121
+ (os .path .join (PROJECTS_DIRECTORY , "using_pyversion" ), ">=3.8,<3.12" ),
122
122
],
123
123
ids = ["option-exists" ],
124
124
)
@@ -140,7 +140,7 @@ def test_detect_python_version_requirement():
140
140
version requirement is used.
141
141
"""
142
142
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"
144
144
145
145
assert detect_python_version_requirement (os .path .join (PROJECTS_DIRECTORY , "empty" )) is None
146
146
@@ -182,15 +182,21 @@ def test_python_version_file_adapt(content, expected):
182
182
183
183
We should convert them to the constraints that connect expects.
184
184
"""
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 :
186
189
tmpfile .write (content )
187
190
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