diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -1558,17 +1558,19 @@ except FileExistsError: pass - # Define a writable temp dir that will be used as cwd while running - # the tests. The name of the dir includes the pid to allow parallel - # testing (see the -j option). - test_cwd = 'test_python_{}'.format(os.getpid()) - test_cwd = os.path.join(TEMPDIR, test_cwd) + # It is not necessary to incorporate the pid here since individual tests + # use support.TESTFN for parallel testing (see issue #15305). + test_cwd = os.path.join(TEMPDIR, 'test_python') + try: + os.mkdir(test_cwd) + except FileExistsError: + pass # Run the tests in a context manager that temporarily changes the CWD to a - # temporary and writable directory. If it's not possible to create or - # change the CWD, the original CWD will be used. The original CWD is + # temporary and writable directory. If it's not possible to change the + # CWD, the original CWD is used. In either case, the original CWD is # available from support.SAVEDCWD. - with support.temp_cwd(test_cwd, quiet=True): + with support.temp_cwd(path=test_cwd, quiet=True): main()