Issue #25654: · python/cpython@a6d865c (original) (raw)
`@@ -455,13 +455,15 @@ def test_stderr_flush(self):
`
455
455
``
456
456
`@classmethod
`
457
457
`def _test_stderr_flush(cls, testfn):
`
458
``
`-
sys.stderr = open(testfn, 'w')
`
``
458
`+
fd = os.open(testfn, os.O_WRONLY | os.O_CREAT | os.O_EXCL)
`
``
459
`+
sys.stderr = open(fd, 'w', closefd=False)
`
459
460
`1/0 # MARKER
`
460
461
``
461
462
``
462
463
`@classmethod
`
463
464
`def _test_sys_exit(cls, reason, testfn):
`
464
``
`-
sys.stderr = open(testfn, 'w')
`
``
465
`+
fd = os.open(testfn, os.O_WRONLY | os.O_CREAT | os.O_EXCL)
`
``
466
`+
sys.stderr = open(fd, 'w', closefd=False)
`
465
467
`sys.exit(reason)
`
466
468
``
467
469
`def test_sys_exit(self):
`
`@@ -472,15 +474,21 @@ def test_sys_exit(self):
`
472
474
`testfn = test.support.TESTFN
`
473
475
`self.addCleanup(test.support.unlink, testfn)
`
474
476
``
475
``
`-
for reason, code in (([1, 2, 3], 1), ('ignore this', 1)):
`
``
477
`+
for reason in (
`
``
478
`+
[1, 2, 3],
`
``
479
`+
'ignore this',
`
``
480
`+
):
`
476
481
`p = self.Process(target=self._test_sys_exit, args=(reason, testfn))
`
477
482
`p.daemon = True
`
478
483
`p.start()
`
479
484
`p.join(5)
`
480
``
`-
self.assertEqual(p.exitcode, code)
`
``
485
`+
self.assertEqual(p.exitcode, 1)
`
481
486
``
482
487
`with open(testfn, 'r') as f:
`
483
``
`-
self.assertEqual(f.read().rstrip(), str(reason))
`
``
488
`+
content = f.read()
`
``
489
`+
self.assertEqual(content.rstrip(), str(reason))
`
``
490
+
``
491
`+
os.unlink(testfn)
`
484
492
``
485
493
`for reason in (True, False, 8):
`
486
494
`p = self.Process(target=sys.exit, args=(reason,))
`