mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
bpo-13236: Flush the output stream more often in unittest (GH-29864)
It can prevent some losses when output to buffered stream.
This commit is contained in:
parent
87a18deda4
commit
f42a06ba27
4 changed files with 54 additions and 5 deletions
|
@ -6,6 +6,7 @@ import subprocess
|
|||
from test import support
|
||||
import unittest
|
||||
import unittest.test
|
||||
from .test_result import BufferedWriter
|
||||
|
||||
|
||||
class Test_TestProgram(unittest.TestCase):
|
||||
|
@ -104,30 +105,39 @@ class Test_TestProgram(unittest.TestCase):
|
|||
program.testNames)
|
||||
|
||||
def test_NonExit(self):
|
||||
stream = BufferedWriter()
|
||||
program = unittest.main(exit=False,
|
||||
argv=["foobar"],
|
||||
testRunner=unittest.TextTestRunner(stream=io.StringIO()),
|
||||
testRunner=unittest.TextTestRunner(stream=stream),
|
||||
testLoader=self.FooBarLoader())
|
||||
self.assertTrue(hasattr(program, 'result'))
|
||||
self.assertIn('\nFAIL: testFail ', stream.getvalue())
|
||||
self.assertTrue(stream.getvalue().endswith('\n\nFAILED (failures=1)\n'))
|
||||
|
||||
|
||||
def test_Exit(self):
|
||||
stream = BufferedWriter()
|
||||
self.assertRaises(
|
||||
SystemExit,
|
||||
unittest.main,
|
||||
argv=["foobar"],
|
||||
testRunner=unittest.TextTestRunner(stream=io.StringIO()),
|
||||
testRunner=unittest.TextTestRunner(stream=stream),
|
||||
exit=True,
|
||||
testLoader=self.FooBarLoader())
|
||||
self.assertIn('\nFAIL: testFail ', stream.getvalue())
|
||||
self.assertTrue(stream.getvalue().endswith('\n\nFAILED (failures=1)\n'))
|
||||
|
||||
|
||||
def test_ExitAsDefault(self):
|
||||
stream = BufferedWriter()
|
||||
self.assertRaises(
|
||||
SystemExit,
|
||||
unittest.main,
|
||||
argv=["foobar"],
|
||||
testRunner=unittest.TextTestRunner(stream=io.StringIO()),
|
||||
testRunner=unittest.TextTestRunner(stream=stream),
|
||||
testLoader=self.FooBarLoader())
|
||||
self.assertIn('\nFAIL: testFail ', stream.getvalue())
|
||||
self.assertTrue(stream.getvalue().endswith('\n\nFAILED (failures=1)\n'))
|
||||
|
||||
|
||||
class InitialisableProgram(unittest.TestProgram):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue