summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-08 08:13:53 (GMT)
committerGitHub <noreply@github.com>2024-06-08 08:13:53 (GMT)
commit863a0bd5154a7dcade03e849ec2ed45fe9f8837f (patch)
tree9ea63fbd9165f35f93c9fc8c53d37b6c8803bacb
parent3be7e91d037059dd98c175f48620191b538b9731 (diff)
downloadcpython-863a0bd5154a7dcade03e849ec2ed45fe9f8837f.zip
cpython-863a0bd5154a7dcade03e849ec2ed45fe9f8837f.tar.gz
cpython-863a0bd5154a7dcade03e849ec2ed45fe9f8837f.tar.bz2
[3.13] gh-120242: Fix handling of `[setUp,tearDown]Class` in `test_datetime` (GH-120243) (#120259)
gh-120242: Fix handling of `[setUp,tearDown]Class` in `test_datetime` (GH-120243) (cherry picked from commit 95f4db88d5ab7d900f05d0418b2a2e77bf9ff126) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
-rw-r--r--Lib/test/test_datetime.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index 3859733..005187f 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -1,5 +1,6 @@
import unittest
import sys
+import functools
from test.support.import_helper import import_fresh_module
@@ -39,21 +40,26 @@ def load_tests(loader, tests, pattern):
for cls in test_classes:
cls.__name__ += suffix
cls.__qualname__ += suffix
- @classmethod
- def setUpClass(cls_, module=module):
- cls_._save_sys_modules = sys.modules.copy()
- sys.modules[TESTS] = module
- sys.modules['datetime'] = module.datetime_module
- if hasattr(module, '_pydatetime'):
- sys.modules['_pydatetime'] = module._pydatetime
- sys.modules['_strptime'] = module._strptime
- @classmethod
- def tearDownClass(cls_):
- sys.modules.clear()
- sys.modules.update(cls_._save_sys_modules)
- cls.setUpClass = setUpClass
- cls.tearDownClass = tearDownClass
- tests.addTests(loader.loadTestsFromTestCase(cls))
+
+ @functools.wraps(cls, updated=())
+ class Wrapper(cls):
+ @classmethod
+ def setUpClass(cls_, module=module):
+ cls_._save_sys_modules = sys.modules.copy()
+ sys.modules[TESTS] = module
+ sys.modules['datetime'] = module.datetime_module
+ if hasattr(module, '_pydatetime'):
+ sys.modules['_pydatetime'] = module._pydatetime
+ sys.modules['_strptime'] = module._strptime
+ super().setUpClass()
+
+ @classmethod
+ def tearDownClass(cls_):
+ super().tearDownClass()
+ sys.modules.clear()
+ sys.modules.update(cls_._save_sys_modules)
+
+ tests.addTests(loader.loadTestsFromTestCase(Wrapper))
return tests