Skip to content

Commit dec9d91

Browse files
[3.12] gh-121200: Fix test_expanduser_pwd2() of test_posixpath (GH-121228) (#121231)
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 e2a97d1 commit dec9d91

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Lib/test/test_posixpath.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,16 @@ def test_expanduser_pwd(self):
347347
"no home directory on VxWorks")
348348
def test_expanduser_pwd2(self):
349349
pwd = import_helper.import_module('pwd')
350-
for entry in pwd.getpwall():
351-
name = entry.pw_name
350+
for all_entry in pwd.getpwall():
351+
name = all_entry.pw_name
352+
353+
# gh-121200: pw_dir can be different between getpwall() and
354+
# getpwnam(), so use getpwnam() pw_dir as expanduser() does.
355+
entry = pwd.getpwnam(name)
352356
home = entry.pw_dir
353357
home = home.rstrip('/') or '/'
354-
with self.subTest(pwd=entry):
358+
359+
with self.subTest(all_entry=all_entry, entry=entry):
355360
self.assertEqual(posixpath.expanduser('~' + name), home)
356361
self.assertEqual(posixpath.expanduser(os.fsencode('~' + name)),
357362
os.fsencode(home))
Lines changed: 3 additions & 0 deletions
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)