mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	[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 95f4db88d5)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
			
			
This commit is contained in:
		
							parent
							
								
									3be7e91d03
								
							
						
					
					
						commit
						863a0bd515
					
				
					 1 changed files with 21 additions and 15 deletions
				
			
		|  | @ -1,5 +1,6 @@ | ||||||
| import unittest | import unittest | ||||||
| import sys | import sys | ||||||
|  | import functools | ||||||
| 
 | 
 | ||||||
| from test.support.import_helper import import_fresh_module | from test.support.import_helper import import_fresh_module | ||||||
| 
 | 
 | ||||||
|  | @ -39,6 +40,9 @@ def load_tests(loader, tests, pattern): | ||||||
|         for cls in test_classes: |         for cls in test_classes: | ||||||
|             cls.__name__ += suffix |             cls.__name__ += suffix | ||||||
|             cls.__qualname__ += suffix |             cls.__qualname__ += suffix | ||||||
|  | 
 | ||||||
|  |             @functools.wraps(cls, updated=()) | ||||||
|  |             class Wrapper(cls): | ||||||
|                 @classmethod |                 @classmethod | ||||||
|                 def setUpClass(cls_, module=module): |                 def setUpClass(cls_, module=module): | ||||||
|                     cls_._save_sys_modules = sys.modules.copy() |                     cls_._save_sys_modules = sys.modules.copy() | ||||||
|  | @ -47,13 +51,15 @@ def setUpClass(cls_, module=module): | ||||||
|                     if hasattr(module, '_pydatetime'): |                     if hasattr(module, '_pydatetime'): | ||||||
|                         sys.modules['_pydatetime'] = module._pydatetime |                         sys.modules['_pydatetime'] = module._pydatetime | ||||||
|                     sys.modules['_strptime'] = module._strptime |                     sys.modules['_strptime'] = module._strptime | ||||||
|  |                     super().setUpClass() | ||||||
|  | 
 | ||||||
|                 @classmethod |                 @classmethod | ||||||
|                 def tearDownClass(cls_): |                 def tearDownClass(cls_): | ||||||
|  |                     super().tearDownClass() | ||||||
|                     sys.modules.clear() |                     sys.modules.clear() | ||||||
|                     sys.modules.update(cls_._save_sys_modules) |                     sys.modules.update(cls_._save_sys_modules) | ||||||
|             cls.setUpClass = setUpClass | 
 | ||||||
|             cls.tearDownClass = tearDownClass |             tests.addTests(loader.loadTestsFromTestCase(Wrapper)) | ||||||
|             tests.addTests(loader.loadTestsFromTestCase(cls)) |  | ||||||
|     return tests |     return tests | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)