Commit 3fbd386 1 parent 46c66af commit 3fbd386 Copy full SHA for 3fbd386
File tree 3 files changed +34
-4
lines changed
3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ Changelog
6
6
7
7
Thanks to Konstantin Baikov in `PR #424 <https://github.com/adamchainz/time-machine/pull/424 >`__.
8
8
9
+ * Fix class decorator for classmethod overrides.
10
+
11
+ Thanks to Pavel Bitiukov for the reproducer in `PR #404 <https://github.com/adamchainz/time-machine/pull/404 >`__.
12
+
9
13
* Avoid calling deprecated ``uuid._load_system_functions() `` on Python 3.9+.
10
14
11
15
Thanks to Nikita Sobolev for the ping in `CPython Issue #113308 <https://github.com/python/cpython/issues/113308 >`__.
Original file line number Diff line number Diff line change @@ -293,24 +293,26 @@ def __call__(
293
293
raise TypeError ("Can only decorate unittest.TestCase subclasses." )
294
294
295
295
# Modify the setUpClass method
296
- orig_setUpClass = wrapped .setUpClass
296
+ orig_setUpClass = wrapped .setUpClass . __func__ # type: ignore[attr-defined]
297
297
298
298
@functools .wraps (orig_setUpClass )
299
299
def setUpClass (cls : type [TestCase ]) -> None :
300
300
self .__enter__ ()
301
301
try :
302
- orig_setUpClass ()
302
+ orig_setUpClass (cls )
303
303
except Exception :
304
304
self .__exit__ (* sys .exc_info ())
305
305
raise
306
306
307
307
wrapped .setUpClass = classmethod (setUpClass ) # type: ignore[assignment]
308
308
309
- orig_tearDownClass = wrapped .tearDownClass
309
+ orig_tearDownClass = (
310
+ wrapped .tearDownClass .__func__ # type: ignore[attr-defined]
311
+ )
310
312
311
313
@functools .wraps (orig_tearDownClass )
312
314
def tearDownClass (cls : type [TestCase ]) -> None :
313
- orig_tearDownClass ()
315
+ orig_tearDownClass (cls )
314
316
self .__exit__ (None , None , None )
315
317
316
318
wrapped .tearDownClass = classmethod ( # type: ignore[assignment]
Original file line number Diff line number Diff line change @@ -558,6 +558,30 @@ class Something:
558
558
assert excinfo .value .args == ("Can only decorate unittest.TestCase subclasses." ,)
559
559
560
560
561
+ @time_machine .travel (EPOCH )
562
+ class ClassDecoratorInheritanceBase (TestCase ):
563
+ prop : bool
564
+
565
+ @classmethod
566
+ def setUpClass (cls ):
567
+ super ().setUpClass ()
568
+ cls .setUpTestData ()
569
+
570
+ @classmethod
571
+ def setUpTestData (cls ) -> None :
572
+ cls .prop = True
573
+
574
+
575
+ class ClassDecoratorInheritanceTests (ClassDecoratorInheritanceBase ):
576
+ @classmethod
577
+ def setUpTestData (cls ) -> None :
578
+ super ().setUpTestData ()
579
+ cls .prop = False
580
+
581
+ def test_ineheritance_correctly_rebound (self ):
582
+ assert self .prop is False
583
+
584
+
561
585
class TestMethodDecorator :
562
586
@time_machine .travel (EPOCH + 95.0 )
563
587
def test_method_decorator (self ):
You can’t perform that action at this time.
0 commit comments