diff -r 811ccdee6f87 Lib/test/test_os.py --- a/Lib/test/test_os.py Wed May 04 09:44:44 2016 +0300 +++ b/Lib/test/test_os.py Sat May 07 17:53:37 2016 +0200 @@ -1314,7 +1314,9 @@ break os.closerange(3, 256) with open({TESTFN!r}, 'rb') as f: - os.dup2(f.fileno(), fd) + new_fd = f.fileno() + if new_fd != fd: + os.dup2(new_fd, fd) sys.stdout.buffer.write(os.urandom(4)) sys.stdout.buffer.write(os.urandom(4)) """.format(TESTFN=support.TESTFN)