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:
Serhiy Storchaka 2021-12-04 20:57:20 +02:00 committed by GitHub
parent 87a18deda4
commit f42a06ba27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 5 deletions

View file

@ -68,6 +68,7 @@ class TextTestResult(result.TestResult):
self.stream.write(self.getDescription(test))
self.stream.write(" ... ")
self.stream.writeln(status)
self.stream.flush()
self._newline = True
def addSubTest(self, test, subtest, err):
@ -121,6 +122,7 @@ class TextTestResult(result.TestResult):
super(TextTestResult, self).addExpectedFailure(test, err)
if self.showAll:
self.stream.writeln("expected failure")
self.stream.flush()
elif self.dots:
self.stream.write("x")
self.stream.flush()
@ -129,6 +131,7 @@ class TextTestResult(result.TestResult):
super(TextTestResult, self).addUnexpectedSuccess(test)
if self.showAll:
self.stream.writeln("unexpected success")
self.stream.flush()
elif self.dots:
self.stream.write("u")
self.stream.flush()
@ -136,6 +139,7 @@ class TextTestResult(result.TestResult):
def printErrors(self):
if self.dots or self.showAll:
self.stream.writeln()
self.stream.flush()
self.printErrorList('ERROR', self.errors)
self.printErrorList('FAIL', self.failures)
@ -145,6 +149,7 @@ class TextTestResult(result.TestResult):
self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
self.stream.writeln(self.separator2)
self.stream.writeln("%s" % err)
self.stream.flush()
class TextTestRunner(object):
@ -239,4 +244,5 @@ class TextTestRunner(object):
self.stream.writeln(" (%s)" % (", ".join(infos),))
else:
self.stream.write("\n")
self.stream.flush()
return result