Skip to content

Commit c503312

Browse files
committed
[test] Add overrides to SingleLineTestResult to support expected failures and unexpected successes. NFC
1 parent d246366 commit c503312

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

test/single_line_runner.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# found in the LICENSE file.
55

66
import shutil
7+
from unittest import TextTestResult
78

89
from color_runner import ColorTextResult, ColorTextRunner
910

@@ -67,6 +68,27 @@ def printErrors(self):
6768
self.stream.write('\n')
6869
super().printErrors()
6970

71+
# Override addExpectedFailure and addUnexpectedSuccess since, for some reason
72+
# these methods in TextTestResult do not use `_write_status` like the other ones.
73+
# TODO(sbc): Send a patch to upstream python to sue `_write_status` in TextTestResult.
74+
def addExpectedFailure(self, test, err):
75+
super(TextTestResult, self).addExpectedFailure(test, err)
76+
if self.showAll:
77+
self._write_status(test, "expected failure")
78+
self.stream.flush()
79+
elif self.dots:
80+
self.stream.write("x")
81+
self.stream.flush()
82+
83+
def addUnexpectedSuccess(self, test):
84+
super(TextTestResult, self).addUnexpectedSuccess(test)
85+
if self.showAll:
86+
self._write_status(test, "unexpected success")
87+
self.stream.flush()
88+
elif self.dots:
89+
self.stream.write("u")
90+
self.stream.flush()
91+
7092

7193
class SingleLineTestRunner(ColorTextRunner):
7294
"""Subclass of TextTestResult that uses SingleLineTestResult"""

0 commit comments

Comments
 (0)