]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46150: ensure `fakeuser` does not exist in `PosixPathTest.test_expanduser` (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 24 Dec 2021 08:32:27 +0000 (00:32 -0800)
committerGitHub <noreply@github.com>
Fri, 24 Dec 2021 08:32:27 +0000 (00:32 -0800)
Ensure `fakeuser` does not exist in `PosixPathTest.test_expanduser`
(cherry picked from commit b8de8b7039cee47465b2af9950b0b9ed2d3f2903)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Lib/test/test_pathlib.py
Misc/NEWS.d/next/Tests/2021-12-23-13-42-15.bpo-46150.RhtADs.rst [new file with mode: 0644]

index 548951a67a6f23c83f4b1cae297083e4a0beb868..1406ed3b12c4a7950b9637300429f885cef824de 100644 (file)
@@ -2443,13 +2443,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 support.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 (file)
index 0000000..8ef9cd9
--- /dev/null
@@ -0,0 +1,2 @@
+Now ``fakename`` in ``test_pathlib.PosixPathTest.test_expanduser`` is checked
+to be non-existent.