Skip to content

Commit 32acfdb

Browse files
[3.13] pythongh-124212: Fix undefined variable in error message in venv (pythonGH-124211) (python#124226)
pythongh-124212: Fix undefined variable in error message in venv (pythonGH-124211) (cherry picked from commit ea7fe1f) Co-authored-by: Jacek <jacek.duszenko@gmail.com>
1 parent 0a868db commit 32acfdb

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Lib/test/test_venv.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,21 @@ def test_unicode_in_batch_file(self):
504504
)
505505
self.assertEqual(out.strip(), '0')
506506

507+
@unittest.skipUnless(os.name == 'nt' and can_symlink(),
508+
'symlinks on Windows')
509+
def test_failed_symlink(self):
510+
"""
511+
Test handling of failed symlinks on Windows.
512+
"""
513+
rmtree(self.env_dir)
514+
env_dir = os.path.join(os.path.realpath(self.env_dir), 'venv')
515+
with patch('os.symlink') as mock_symlink:
516+
mock_symlink.side_effect = OSError()
517+
builder = venv.EnvBuilder(clear=True, symlinks=True)
518+
_, err = self.run_with_capture(builder.create, env_dir)
519+
filepath_regex = r"'[A-Z]:\\\\(?:[^\\\\]+\\\\)*[^\\\\]+'"
520+
self.assertRegex(err, rf"Unable to symlink {filepath_regex} to {filepath_regex}")
521+
507522
@requireVenvCreate
508523
def test_multiprocessing(self):
509524
"""

Lib/venv/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def setup_python(self, context):
393393
os.symlink(src, dest)
394394
to_unlink.append(dest)
395395
except OSError:
396-
logger.warning('Unable to symlink %r to %r', src, dst)
396+
logger.warning('Unable to symlink %r to %r', src, dest)
397397
do_copies = True
398398
for f in to_unlink:
399399
try:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix invalid variable in :mod:`venv` handling of failed symlink on Windows

0 commit comments

Comments
 (0)