gh-113267: Revert "gh-106584: Fix exit code for unittest in Python 3.12 (#106588)" (GH-114470)

This reverts commit 8fc071345b.
This commit is contained in:
Serhiy Storchaka 2024-02-04 17:27:42 +02:00 committed by GitHub
parent ca715e56a1
commit ecabff98c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 14 additions and 16 deletions

View File

@ -571,7 +571,7 @@ class TestDiscovery(unittest.TestCase):
result = unittest.TestResult()
suite.run(result)
self.assertEqual(len(result.skipped), 1)
self.assertEqual(result.testsRun, 0)
self.assertEqual(result.testsRun, 1)
self.assertEqual(import_calls, ['my_package'])
# Check picklability

View File

@ -103,16 +103,16 @@ class Test_TestSkipping(unittest.TestCase):
result = LoggingResult(events)
self.assertIs(suite.run(result), result)
self.assertEqual(len(result.skipped), 1)
expected = ['addSkip', 'stopTest', 'startTest',
'addSuccess', 'stopTest']
expected = ['startTest', 'addSkip', 'stopTest',
'startTest', 'addSuccess', 'stopTest']
self.assertEqual(events, expected)
self.assertEqual(result.testsRun, 1)
self.assertEqual(result.testsRun, 2)
self.assertEqual(result.skipped, [(test_do_skip, "testing")])
self.assertTrue(result.wasSuccessful())
events = []
result = test_do_skip.run()
self.assertEqual(events, ['startTestRun', 'addSkip',
self.assertEqual(events, ['startTestRun', 'startTest', 'addSkip',
'stopTest', 'stopTestRun'])
self.assertEqual(result.skipped, [(test_do_skip, "testing")])
@ -135,13 +135,13 @@ class Test_TestSkipping(unittest.TestCase):
test = Foo("test_1")
suite = unittest.TestSuite([test])
self.assertIs(suite.run(result), result)
self.assertEqual(events, ['addSkip', 'stopTest'])
self.assertEqual(events, ['startTest', 'addSkip', 'stopTest'])
self.assertEqual(result.skipped, [(test, "testing")])
self.assertEqual(record, [])
events = []
result = test.run()
self.assertEqual(events, ['startTestRun', 'addSkip',
self.assertEqual(events, ['startTestRun', 'startTest', 'addSkip',
'stopTest', 'stopTestRun'])
self.assertEqual(result.skipped, [(test, "testing")])
self.assertEqual(record, [])

View File

@ -606,6 +606,7 @@ class TestCase(object):
else:
stopTestRun = None
result.startTest(self)
try:
testMethod = getattr(self, self._testMethodName)
if (getattr(self.__class__, "__unittest_skip__", False) or
@ -616,9 +617,6 @@ class TestCase(object):
_addSkip(result, self, skip_why)
return result
# Increase the number of tests only if it hasn't been skipped
result.startTest(self)
expecting_failure = (
getattr(self, "__unittest_expecting_failure__", False) or
getattr(testMethod, "__unittest_expecting_failure__", False)

View File

@ -97,12 +97,10 @@ class TestResult(object):
sys.stdout = self._original_stdout
sys.stderr = self._original_stderr
if self._stdout_buffer is not None:
self._stdout_buffer.seek(0)
self._stdout_buffer.truncate()
if self._stderr_buffer is not None:
self._stderr_buffer.seek(0)
self._stderr_buffer.truncate()
self._stdout_buffer.seek(0)
self._stdout_buffer.truncate()
self._stderr_buffer.seek(0)
self._stderr_buffer.truncate()
def stopTestRun(self):
"""Called once after all tests are executed.

View File

@ -0,0 +1,2 @@
Revert changes in :gh:`106584` which made calls of ``TestResult`` methods
``startTest()`` and ``stopTest()`` unbalanced.