diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2021-12-24 11:07:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-24 00:07:50 -0800 |
commit | b8de8b7039cee47465b2af9950b0b9ed2d3f2903 (patch) | |
tree | 8fe2db9052f0b279c2e0ad6d5cd3a0cec5309a56 | |
parent | d8880677a79ba4e70bbe7583eecf573bfceb7e98 (diff) | |
download | cpython-git-b8de8b7039cee47465b2af9950b0b9ed2d3f2903.tar.gz |
bpo-46150: ensure `fakeuser` does not exist in `PosixPathTest.test_expanduser` (GH-30240)
Ensure `fakeuser` does not exist in `PosixPathTest.test_expanduser`
-rw-r--r-- | Lib/test/test_pathlib.py | 18 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Tests/2021-12-23-13-42-15.bpo-46150.RhtADs.rst | 2 |
2 files changed, 15 insertions, 5 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 2268d36b06..555c7ee795 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) diff --git a/Misc/NEWS.d/next/Tests/2021-12-23-13-42-15.bpo-46150.RhtADs.rst b/Misc/NEWS.d/next/Tests/2021-12-23-13-42-15.bpo-46150.RhtADs.rst new file mode 100644 index 0000000000..8ef9cd9b4a --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2021-12-23-13-42-15.bpo-46150.RhtADs.rst @@ -0,0 +1,2 @@ +Now ``fakename`` in ``test_pathlib.PosixPathTest.test_expanduser`` is checked +to be non-existent. |