Skip to content

Commit 010bf92

Browse files
[3.13] gh-121200: Fix test_expanduser_pwd2() of test_posixpath (GH-121228) (#121232)
gh-121200: Fix test_expanduser_pwd2() of test_posixpath (GH-121228) Call getpwnam() to get pw_dir, since it can be different than getpwall() pw_dir. (cherry picked from commit 02cb5fd) Co-authored-by: Victor Stinner <[email protected]>
1 parent 7bd67d5 commit 010bf92

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Lib/test/test_posixpath.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,16 @@ def test_expanduser_pwd(self):
359359
"no home directory on VxWorks")
360360
def test_expanduser_pwd2(self):
361361
pwd = import_helper.import_module('pwd')
362-
for entry in pwd.getpwall():
363-
name = entry.pw_name
362+
for all_entry in pwd.getpwall():
363+
name = all_entry.pw_name
364+
365+
# gh-121200: pw_dir can be different between getpwall() and
366+
# getpwnam(), so use getpwnam() pw_dir as expanduser() does.
367+
entry = pwd.getpwnam(name)
364368
home = entry.pw_dir
365369
home = home.rstrip('/') or '/'
366-
with self.subTest(pwd=entry):
370+
371+
with self.subTest(all_entry=all_entry, entry=entry):
367372
self.assertEqual(posixpath.expanduser('~' + name), home)
368373
self.assertEqual(posixpath.expanduser(os.fsencode('~' + name)),
369374
os.fsencode(home))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix ``test_expanduser_pwd2()`` of ``test_posixpath``. Call ``getpwnam()``
2+
to get ``pw_dir``, since it can be different than ``getpwall()`` ``pw_dir``.
3+
Patch by Victor Stinner.

0 commit comments

Comments
 (0)