summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pathlib.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-12-24 08:31:13 (GMT)
committerGitHub <noreply@github.com>2021-12-24 08:31:13 (GMT)
commit8005e22c9c71708ead0e5b16e55e005844c5131f (patch)
tree1a37fb10c80966d9b61939e69da529575189d62a /Lib/test/test_pathlib.py
parent1c77aa9fc3c105053167d519607565068a2688b5 (diff)
downloadcpython-8005e22c9c71708ead0e5b16e55e005844c5131f.zip
cpython-8005e22c9c71708ead0e5b16e55e005844c5131f.tar.gz
cpython-8005e22c9c71708ead0e5b16e55e005844c5131f.tar.bz2
bpo-46150: ensure `fakeuser` does not exist in `PosixPathTest.test_expanduser` (GH-30240)
Ensure `fakeuser` does not exist in `PosixPathTest.test_expanduser` (cherry picked from commit b8de8b7039cee47465b2af9950b0b9ed2d3f2903) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Diffstat (limited to 'Lib/test/test_pathlib.py')
-rw-r--r--Lib/test/test_pathlib.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index 2268d36..555c7ee 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -2558,13 +2558,21 @@ class PosixPathTest(_BasePathTest, unittest.TestCase):
othername = username
otherhome = userhome
+ fakename = 'fakeuser'
+ # This user can theoretically exist on a test runner. Create unique name:
+ try:
+ while pwd.getpwnam(fakename):
+ fakename += '1'
+ except KeyError:
+ pass # Non-existent name found
+
p1 = P('~/Documents')
- p2 = P('~' + username + '/Documents')
- p3 = P('~' + othername + '/Documents')
- p4 = P('../~' + username + '/Documents')
- p5 = P('/~' + username + '/Documents')
+ p2 = P(f'~{username}/Documents')
+ p3 = P(f'~{othername}/Documents')
+ p4 = P(f'../~{username}/Documents')
+ p5 = P(f'/~{username}/Documents')
p6 = P('')
- p7 = P('~fake800813user/Documents')
+ p7 = P(f'~{fakename}/Documents')
with os_helper.EnvironmentVarGuard() as env:
env.pop('HOME', None)