3
3
4
4
import pytest
5
5
from django .core .cache import caches
6
+ from pytest import LogCaptureFixture
6
7
from pytest_django .fixtures import SettingsWrapper
7
8
from redis .exceptions import ConnectionError
8
9
@@ -22,8 +23,10 @@ def reverse_key(key: str) -> str:
22
23
def ignore_exceptions_cache (settings : SettingsWrapper ) -> RedisCache :
23
24
caches_setting = copy .deepcopy (settings .CACHES )
24
25
caches_setting ["doesnotexist" ]["OPTIONS" ]["IGNORE_EXCEPTIONS" ] = True
26
+ caches_setting ["doesnotexist" ]["OPTIONS" ]["LOG_IGNORED_EXCEPTIONS" ] = True
25
27
settings .CACHES = caches_setting
26
28
settings .DJANGO_REDIS_IGNORE_EXCEPTIONS = True
29
+ settings .DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True
27
30
return cast (RedisCache , caches ["doesnotexist" ])
28
31
29
32
@@ -34,12 +37,22 @@ def test_get_django_omit_exceptions_many_returns_default_arg(
34
37
assert ignore_exceptions_cache .get_many (["key1" , "key2" , "key3" ]) == {}
35
38
36
39
37
- def test_get_django_omit_exceptions (ignore_exceptions_cache : RedisCache ):
40
+ def test_get_django_omit_exceptions (
41
+ caplog : LogCaptureFixture , ignore_exceptions_cache : RedisCache
42
+ ):
38
43
assert ignore_exceptions_cache ._ignore_exceptions is True
44
+ assert ignore_exceptions_cache ._log_ignored_exceptions is True
45
+
39
46
assert ignore_exceptions_cache .get ("key" ) is None
40
47
assert ignore_exceptions_cache .get ("key" , "default" ) == "default"
41
48
assert ignore_exceptions_cache .get ("key" , default = "default" ) == "default"
42
49
50
+ assert len (caplog .records ) == 3
51
+ assert all (
52
+ record .levelname == "ERROR" and record .msg == "Exception ignored"
53
+ for record in caplog .records
54
+ )
55
+
43
56
44
57
def test_get_django_omit_exceptions_priority_1 (settings : SettingsWrapper ):
45
58
caches_setting = copy .deepcopy (settings .CACHES )
0 commit comments