summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorEliseevEgor <egor.eliseev@jetbrains.com>2023-09-22 12:26:27 (GMT)
committerGitHub <noreply@github.com>2023-09-22 12:26:27 (GMT)
commit8fc071345b50dd3de61ebeeaa287ccef21d061b2 (patch)
treeab32d98e61d9b937bfb9377529f89c79799012df /Lib/unittest
parent34ddcc3fa118168901fa0d3a69b3b5444fc2f943 (diff)
downloadcpython-8fc071345b50dd3de61ebeeaa287ccef21d061b2.zip
cpython-8fc071345b50dd3de61ebeeaa287ccef21d061b2.tar.gz
cpython-8fc071345b50dd3de61ebeeaa287ccef21d061b2.tar.bz2
gh-106584: Fix exit code for unittest in Python 3.12 (#106588)
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.