1
+ import logging
2
+ from datetime import datetime
1
3
from unittest .mock import patch
2
4
3
- from django .test import TestCase
4
5
from django .core .cache import cache
6
+ from django .test import TestCase
5
7
6
8
from cache_helper .decorators import cached , cached_class_method , cached_instance_method
7
9
from cache_helper .exceptions import CacheHelperException , CacheKeyCreationError
8
10
from cache_helper .interfaces import CacheHelperCacheable
9
11
10
- from datetime import datetime
11
-
12
+ DISABLE_LOGGING_BELOW = logging .ERROR
12
13
GLOBAL_COUNTER = 200
13
14
14
15
@@ -112,9 +113,15 @@ def get_product(self):
112
113
113
114
114
115
class CachedInstanceMethodTests (TestCase ):
116
+
117
+ def setUp (self ):
118
+ logging .disable (DISABLE_LOGGING_BELOW )
119
+ super ().setUp ()
120
+
115
121
def tearDown (self ):
116
122
super ().tearDown ()
117
123
cache .clear ()
124
+ logging .disable (logging .NOTSET )
118
125
119
126
def test_exception_during_cache_retrieval (self ):
120
127
incrementer = Incrementer (100 )
@@ -272,6 +279,11 @@ def test_invalidate_instance_method(self):
272
279
273
280
274
281
class CachedClassMethodTests (TestCase ):
282
+
283
+ def setUp (self ):
284
+ logging .disable (DISABLE_LOGGING_BELOW )
285
+ super ().setUp ()
286
+
275
287
def tearDown (self ):
276
288
super ().tearDown ()
277
289
@@ -281,6 +293,7 @@ def tearDown(self):
281
293
AnotherIncrementer .class_counter = 500
282
294
283
295
cache .clear ()
296
+ logging .disable (logging .NOTSET )
284
297
285
298
def test_exception_during_cache_retrieval (self ):
286
299
# Hasn't been computed before, so the function actually gets called
@@ -414,12 +427,17 @@ def test_invalidate_class_method(self):
414
427
415
428
416
429
class CachedStaticMethodTests (TestCase ):
430
+ def setUp (self ):
431
+ logging .disable (DISABLE_LOGGING_BELOW )
432
+ super ().setUp ()
433
+
417
434
def tearDown (self ):
418
435
super ().tearDown ()
419
436
420
437
global GLOBAL_COUNTER
421
438
GLOBAL_COUNTER = 200
422
439
cache .clear ()
440
+ logging .disable (logging .NOTSET )
423
441
424
442
def test_exception_during_cache_retrieval (self ):
425
443
datetime_1 = Incrementer .get_datetime (1 )
0 commit comments