@@ -186,6 +186,120 @@ fn create_venv_ignores_virtual_env_variable() {
186
186
) ;
187
187
}
188
188
189
+ #[ test]
190
+ fn create_venv_reads_request_from_python_version_file ( ) {
191
+ let context = VenvTestContext :: new ( & [ "3.12" ] ) ;
192
+ let python_path = python_path_with_versions ( & context. temp_dir , & [ "3.11" , "3.12" ] )
193
+ . expect ( "Failed to create Python test path" ) ;
194
+
195
+ // Without the file, we should use the first on the PATH
196
+ uv_snapshot ! ( context. filters( ) , context. venv_command( )
197
+ . arg( "--preview" ) . env( "UV_TEST_PYTHON_PATH" , & python_path) , @r###"
198
+ success: true
199
+ exit_code: 0
200
+ ----- stdout -----
201
+
202
+ ----- stderr -----
203
+ Using Python 3.11.9 interpreter at: [PATH]
204
+ Creating virtualenv at: .venv
205
+ Activate with: source .venv/bin/activate
206
+ "###
207
+ ) ;
208
+
209
+ // With a version file, we should prefer that version
210
+ context
211
+ . temp_dir
212
+ . child ( ".python-version" )
213
+ . write_str ( "3.12" )
214
+ . unwrap ( ) ;
215
+
216
+ uv_snapshot ! ( context. filters( ) , context. venv_command( )
217
+ . arg( "--preview" ) . env( "UV_TEST_PYTHON_PATH" , & python_path) , @r###"
218
+ success: true
219
+ exit_code: 0
220
+ ----- stdout -----
221
+
222
+ ----- stderr -----
223
+ Using Python 3.12.[X] interpreter at: [PATH]
224
+ Creating virtualenv at: .venv
225
+ Activate with: source .venv/bin/activate
226
+ "###
227
+ ) ;
228
+
229
+ context. venv . assert ( predicates:: path:: is_dir ( ) ) ;
230
+ }
231
+
232
+ #[ test]
233
+ fn create_venv_reads_request_from_python_versions_file ( ) {
234
+ let context = VenvTestContext :: new ( & [ "3.12" ] ) ;
235
+ let python_path = python_path_with_versions ( & context. temp_dir , & [ "3.11" , "3.12" ] )
236
+ . expect ( "Failed to create Python test path" ) ;
237
+
238
+ // Without the file, we should use the first on the PATH
239
+ uv_snapshot ! ( context. filters( ) , context. venv_command( )
240
+ . arg( "--preview" ) . env( "UV_TEST_PYTHON_PATH" , & python_path) , @r###"
241
+ success: true
242
+ exit_code: 0
243
+ ----- stdout -----
244
+
245
+ ----- stderr -----
246
+ Using Python 3.11.9 interpreter at: [PATH]
247
+ Creating virtualenv at: .venv
248
+ Activate with: source .venv/bin/activate
249
+ "###
250
+ ) ;
251
+
252
+ // With a versions file, we should prefer the first listed version
253
+ context
254
+ . temp_dir
255
+ . child ( ".python-versions" )
256
+ . write_str ( "3.12\n 3.11" )
257
+ . unwrap ( ) ;
258
+
259
+ uv_snapshot ! ( context. filters( ) , context. venv_command( )
260
+ . arg( "--preview" ) . env( "UV_TEST_PYTHON_PATH" , & python_path) , @r###"
261
+ success: true
262
+ exit_code: 0
263
+ ----- stdout -----
264
+
265
+ ----- stderr -----
266
+ Using Python 3.12.[X] interpreter at: [PATH]
267
+ Creating virtualenv at: .venv
268
+ Activate with: source .venv/bin/activate
269
+ "###
270
+ ) ;
271
+
272
+ context. venv . assert ( predicates:: path:: is_dir ( ) ) ;
273
+ }
274
+
275
+ #[ test]
276
+ fn create_venv_explicit_request_takes_priority_over_python_version_file ( ) {
277
+ let context = VenvTestContext :: new ( & [ "3.12" ] ) ;
278
+ let python_path = python_path_with_versions ( & context. temp_dir , & [ "3.11" , "3.12" ] )
279
+ . expect ( "Failed to create Python test path" ) ;
280
+
281
+ context
282
+ . temp_dir
283
+ . child ( ".python-version" )
284
+ . write_str ( "3.12" )
285
+ . unwrap ( ) ;
286
+
287
+ uv_snapshot ! ( context. filters( ) , context. venv_command( )
288
+ . arg( "--preview" ) . arg( "--python" ) . arg( "3.11" ) . env( "UV_TEST_PYTHON_PATH" , & python_path) , @r###"
289
+ success: true
290
+ exit_code: 0
291
+ ----- stdout -----
292
+
293
+ ----- stderr -----
294
+ Using Python 3.11.9 interpreter at: [PATH]
295
+ Creating virtualenv at: .venv
296
+ Activate with: source .venv/bin/activate
297
+ "###
298
+ ) ;
299
+
300
+ context. venv . assert ( predicates:: path:: is_dir ( ) ) ;
301
+ }
302
+
189
303
#[ test]
190
304
fn seed ( ) {
191
305
let context = VenvTestContext :: new ( & [ "3.12" ] ) ;
0 commit comments