summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-10-02 15:18:41 (GMT)
committerGitHub <noreply@github.com>2023-10-02 15:18:41 (GMT)
commit551aa6ab9419109a80ad53900ad930e9b7f2e40d (patch)
tree8a328a2aa99be63258f8c2827749551ae5071f2d /Lib/unittest
parent84ef145d854832f8521ea38468071ad210b6365c (diff)
downloadcpython-551aa6ab9419109a80ad53900ad930e9b7f2e40d.zip
cpython-551aa6ab9419109a80ad53900ad930e9b7f2e40d.tar.gz
cpython-551aa6ab9419109a80ad53900ad930e9b7f2e40d.tar.bz2
[3.12] gh-106584: Fix exit code for unittest in Python 3.12 (GH-106588) (#109725)
gh-106584: Fix exit code for unittest in Python 3.12 (GH-106588) (cherry picked from commit 8fc071345b50dd3de61ebeeaa287ccef21d061b2) Co-authored-by: EliseevEgor <egor.eliseev@jetbrains.com> Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/case.py4
-rw-r--r--Lib/unittest/result.py10
2 files changed, 9 insertions, 5 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 001b640..8115574 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -606,7 +606,6 @@ class TestCase(object):
else:
stopTestRun = None
- result.startTest(self)
try:
testMethod = getattr(self, self._testMethodName)
if (getattr(self.__class__, "__unittest_skip__", False) or
@@ -617,6 +616,9 @@ 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)
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py
index 3ace0a5..9e56f65 100644
--- a/Lib/unittest/result.py
+++ b/Lib/unittest/result.py
@@ -97,10 +97,12 @@ class TestResult(object):
sys.stdout = self._original_stdout
sys.stderr = self._original_stderr
- self._stdout_buffer.seek(0)
- self._stdout_buffer.truncate()
- self._stderr_buffer.seek(0)
- self._stderr_buffer.truncate()
+ 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()
def stopTestRun(self):
"""Called once after all tests are executed.