Skip to content

Commit 41a5ce1

Browse files
Abseil Teamcopybara-github
authored andcommitted
Remove monkey-patch for unittest.TestResult.wasSuccessful
This issue was fixed upstream in CPython 3.4 python/cpython@5a6d4bf PiperOrigin-RevId: 843202640
1 parent a870f10 commit 41a5ce1

File tree

1 file changed

+0
-32
lines changed

1 file changed

+0
-32
lines changed

absl/testing/absltest.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -222,38 +222,6 @@ def _get_default_randomize_ordering_seed() -> int:
222222
flags.DEFINE_string('xml_output_file', '', 'File to store XML test results')
223223

224224

225-
# We might need to monkey-patch TestResult so that it stops considering an
226-
# unexpected pass as a "successful result". For details, see
227-
# http://bugs.python.org/issue20165
228-
def _monkey_patch_test_result_for_unexpected_passes() -> None:
229-
"""Workaround for <http://bugs.python.org/issue20165>."""
230-
231-
def wasSuccessful(self) -> bool:
232-
"""Tells whether or not this result was a success.
233-
234-
Any unexpected pass is to be counted as a non-success.
235-
236-
Args:
237-
self: The TestResult instance.
238-
239-
Returns:
240-
Whether or not this result was a success.
241-
"""
242-
return (len(self.failures) == len(self.errors) ==
243-
len(self.unexpectedSuccesses) == 0)
244-
245-
test_result = unittest.TestResult()
246-
test_result.addUnexpectedSuccess(unittest.FunctionTestCase(lambda: None))
247-
if test_result.wasSuccessful(): # The bug is present.
248-
unittest.TestResult.wasSuccessful = wasSuccessful # type: ignore[method-assign]
249-
if test_result.wasSuccessful(): # Warn the user if our hot-fix failed.
250-
sys.stderr.write('unittest.result.TestResult monkey patch to report'
251-
' unexpected passes as failures did not work.\n')
252-
253-
254-
_monkey_patch_test_result_for_unexpected_passes()
255-
256-
257225
def _open(
258226
filepath: str, mode: str, _open_func: Callable[..., IO[AnyStr]] = open
259227
) -> IO[AnyStr]:

0 commit comments

Comments
 (0)