@@ -6,7 +6,7 @@ use indoc::indoc;
6
6
use uv_python:: platform:: { Arch , Os } ;
7
7
use uv_static:: EnvVars ;
8
8
9
- use crate :: common:: { uv_snapshot, TestContext } ;
9
+ use crate :: common:: { uv_snapshot, venv_bin_path , TestContext } ;
10
10
11
11
#[ test]
12
12
fn python_find ( ) {
@@ -560,3 +560,57 @@ fn python_find_unsupported_version() {
560
560
error: Invalid version request: Python <3.13 does not support free-threading but 3.12t was requested.
561
561
"### ) ;
562
562
}
563
+
564
+ #[ test]
565
+ fn python_find_venv_invalid ( ) {
566
+ let context: TestContext = TestContext :: new ( "3.12" )
567
+ // Enable additional filters for Windows compatibility
568
+ . with_filtered_exe_suffix ( )
569
+ . with_filtered_python_names ( )
570
+ . with_filtered_virtualenv_bin ( ) ;
571
+
572
+ // We find the virtual environment
573
+ uv_snapshot ! ( context. filters( ) , context. python_find( ) , @r###"
574
+ success: true
575
+ exit_code: 0
576
+ ----- stdout -----
577
+ [VENV]/[BIN]/python
578
+
579
+ ----- stderr -----
580
+ "### ) ;
581
+
582
+ // If the binaries are missing from a virtual environment, we fail
583
+ fs_err:: remove_dir_all ( venv_bin_path ( & context. venv ) ) . unwrap ( ) ;
584
+
585
+ uv_snapshot ! ( context. filters( ) , context. python_find( ) , @r###"
586
+ success: false
587
+ exit_code: 2
588
+ ----- stdout -----
589
+
590
+ ----- stderr -----
591
+ error: Failed to inspect Python interpreter from active virtual environment at `.venv/[BIN]/python`
592
+ Caused by: Python interpreter not found at `[VENV]/[BIN]/python`
593
+ "### ) ;
594
+
595
+ // Unless the virtual environment is not active
596
+ uv_snapshot ! ( context. filters( ) , context. python_find( ) . env_remove( "VIRTUAL_ENV" ) , @r###"
597
+ success: true
598
+ exit_code: 0
599
+ ----- stdout -----
600
+ [PYTHON-3.12]
601
+
602
+ ----- stderr -----
603
+ "### ) ;
604
+
605
+ // If there's not a `pyvenv.cfg` file, it's also non-fatal, we ignore the environment
606
+ fs_err:: remove_file ( context. venv . join ( "pyvenv.cfg" ) ) . unwrap ( ) ;
607
+
608
+ uv_snapshot ! ( context. filters( ) , context. python_find( ) , @r###"
609
+ success: true
610
+ exit_code: 0
611
+ ----- stdout -----
612
+ [PYTHON-3.12]
613
+
614
+ ----- stderr -----
615
+ "### ) ;
616
+ }
0 commit comments