@@ -608,6 +608,33 @@ def test_failed_symlink(self):
608608 filepath_regex = r"'[A-Z]:\\\\(?:[^\\\\]+\\\\)*[^\\\\]+'"
609609 self .assertRegex (err , rf"Unable to symlink { filepath_regex } to { filepath_regex } " )
610610
611+ @requireVenvCreate
612+ @unittest .skipIf (os .name == 'nt' , 'not relevant on Windows' )
613+ @unittest .skipUnless (can_symlink (), 'Needs symlinks' )
614+ def test_broken_symlink_in_existing_venv (self ):
615+ """
616+ Test creating a venv when a stale venv with broken symlinks exists.
617+ """
618+ bindir = os .path .join (self .env_dir , self .bindir )
619+ os .makedirs (bindir )
620+ python = os .path .join (bindir , 'python3' )
621+ os .symlink ('/path/to/deleted/conda/env/bin/python3' , python )
622+ self .assertTrue (os .path .islink (python ))
623+ self .assertFalse (os .path .exists (python ))
624+
625+ builder = venv .EnvBuilder (with_pip = False , symlinks = True )
626+ self .run_with_capture (builder .create , self .env_dir )
627+ self .assertTrue (os .path .islink (python ))
628+ self .assertTrue (os .path .exists (python ))
629+
630+ rmtree (self .env_dir )
631+ os .makedirs (bindir )
632+ os .symlink ('/path/to/deleted/conda/env/bin/python3' , python )
633+ builder = venv .EnvBuilder (with_pip = False , symlinks = False )
634+ self .run_with_capture (builder .create , self .env_dir )
635+ self .assertFalse (os .path .islink (python ))
636+ self .assertTrue (os .path .exists (python ))
637+
611638 @requireVenvCreate
612639 def test_multiprocessing (self ):
613640 """
0 commit comments