aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Lib/unittest
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-12-23 19:39:02 +0300
committershadchin <shadchin@yandex-team.com>2024-12-23 19:54:20 +0300
commit65a5bf9d37a3b29eb394f560b9a09318196c40e8 (patch)
treee5cd68fb0682b2388e52d9806bb87adc348e21a8 /contrib/tools/python3/Lib/unittest
parenta1dd87a52878ab3e46e5fd2dba5ecbba6113d7e0 (diff)
downloadydb-65a5bf9d37a3b29eb394f560b9a09318196c40e8.tar.gz
Update Python 3 to 3.12.8
commit_hash:c20045b8a987d8720e1f3328270357491d5530f3
Diffstat (limited to 'contrib/tools/python3/Lib/unittest')
-rw-r--r--contrib/tools/python3/Lib/unittest/async_case.py1
-rw-r--r--contrib/tools/python3/Lib/unittest/mock.py9
2 files changed, 10 insertions, 0 deletions
diff --git a/contrib/tools/python3/Lib/unittest/async_case.py b/contrib/tools/python3/Lib/unittest/async_case.py
index bd2a471156..2abfb79079 100644
--- a/contrib/tools/python3/Lib/unittest/async_case.py
+++ b/contrib/tools/python3/Lib/unittest/async_case.py
@@ -5,6 +5,7 @@ import warnings
from .case import TestCase
+__unittest = True
class IsolatedAsyncioTestCase(TestCase):
# Names intentionally have a long prefix
diff --git a/contrib/tools/python3/Lib/unittest/mock.py b/contrib/tools/python3/Lib/unittest/mock.py
index 3e9791b22d..c4ce8f8a3e 100644
--- a/contrib/tools/python3/Lib/unittest/mock.py
+++ b/contrib/tools/python3/Lib/unittest/mock.py
@@ -1329,6 +1329,7 @@ class _patch(object):
self.autospec = autospec
self.kwargs = kwargs
self.additional_patchers = []
+ self.is_started = False
def copy(self):
@@ -1441,6 +1442,9 @@ class _patch(object):
def __enter__(self):
"""Perform the patch."""
+ if self.is_started:
+ raise RuntimeError("Patch is already started")
+
new, spec, spec_set = self.new, self.spec, self.spec_set
autospec, kwargs = self.autospec, self.kwargs
new_callable = self.new_callable
@@ -1572,6 +1576,7 @@ class _patch(object):
self.temp_original = original
self.is_local = local
self._exit_stack = contextlib.ExitStack()
+ self.is_started = True
try:
setattr(self.target, self.attribute, new_attr)
if self.attribute_name is not None:
@@ -1591,6 +1596,9 @@ class _patch(object):
def __exit__(self, *exc_info):
"""Undo the patch."""
+ if not self.is_started:
+ return
+
if self.is_local and self.temp_original is not DEFAULT:
setattr(self.target, self.attribute, self.temp_original)
else:
@@ -1607,6 +1615,7 @@ class _patch(object):
del self.target
exit_stack = self._exit_stack
del self._exit_stack
+ self.is_started = False
return exit_stack.__exit__(*exc_info)