33
44import pytest
55from django .core .cache import caches
6+ from pytest import LogCaptureFixture
67from pytest_django .fixtures import SettingsWrapper
78from redis .exceptions import ConnectionError
89
@@ -22,8 +23,10 @@ def reverse_key(key: str) -> str:
2223def ignore_exceptions_cache (settings : SettingsWrapper ) -> RedisCache :
2324 caches_setting = copy .deepcopy (settings .CACHES )
2425 caches_setting ["doesnotexist" ]["OPTIONS" ]["IGNORE_EXCEPTIONS" ] = True
26+ caches_setting ["doesnotexist" ]["OPTIONS" ]["LOG_IGNORED_EXCEPTIONS" ] = True
2527 settings .CACHES = caches_setting
2628 settings .DJANGO_REDIS_IGNORE_EXCEPTIONS = True
29+ settings .DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True
2730 return cast (RedisCache , caches ["doesnotexist" ])
2831
2932
@@ -34,12 +37,22 @@ def test_get_django_omit_exceptions_many_returns_default_arg(
3437 assert ignore_exceptions_cache .get_many (["key1" , "key2" , "key3" ]) == {}
3538
3639
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+ ):
3843 assert ignore_exceptions_cache ._ignore_exceptions is True
44+ assert ignore_exceptions_cache ._log_ignored_exceptions is True
45+
3946 assert ignore_exceptions_cache .get ("key" ) is None
4047 assert ignore_exceptions_cache .get ("key" , "default" ) == "default"
4148 assert ignore_exceptions_cache .get ("key" , default = "default" ) == "default"
4249
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+
4356
4457def test_get_django_omit_exceptions_priority_1 (settings : SettingsWrapper ):
4558 caches_setting = copy .deepcopy (settings .CACHES )
0 commit comments