File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -2558,13 +2558,21 @@ def test_expanduser(self):
25582558 othername = username
25592559 otherhome = userhome
25602560
2561+ fakename = 'fakeuser'
2562+ # This user can theoretically exist on a test runner. Create unique name:
2563+ try :
2564+ while pwd .getpwnam (fakename ):
2565+ fakename += '1'
2566+ except KeyError :
2567+ pass # Non-existent name found
2568+
25612569 p1 = P ('~/Documents' )
2562- p2 = P ('~' + username + ' /Documents' )
2563- p3 = P ('~' + othername + ' /Documents' )
2564- p4 = P ('../~' + username + ' /Documents' )
2565- p5 = P ('/~' + username + ' /Documents' )
2570+ p2 = P (f'~ { username } /Documents' )
2571+ p3 = P (f'~ { othername } /Documents' )
2572+ p4 = P (f '../~{ username } /Documents' )
2573+ p5 = P (f '/~{ username } /Documents' )
25662574 p6 = P ('' )
2567- p7 = P ('~fake800813user /Documents' )
2575+ p7 = P (f'~ { fakename } /Documents' )
25682576
25692577 with os_helper .EnvironmentVarGuard () as env :
25702578 env .pop ('HOME' , None )
Original file line number Diff line number Diff line change 1+ Now ``fakename `` in ``test_pathlib.PosixPathTest.test_expanduser `` is checked
2+ to be non-existent.
You can’t perform that action at this time.
0 commit comments