Skip to content

Commit 52fc78d

Browse files
committed
Test that exceptions are logged
1 parent 8a54fa5 commit 52fc78d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/test_cache_options.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55
from django.core.cache import caches
6+
from pytest import LogCaptureFixture
67
from pytest_django.fixtures import SettingsWrapper
78
from redis.exceptions import ConnectionError
89

@@ -22,8 +23,10 @@ def reverse_key(key: str) -> str:
2223
def 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

4457
def test_get_django_omit_exceptions_priority_1(settings: SettingsWrapper):
4558
caches_setting = copy.deepcopy(settings.CACHES)

0 commit comments

Comments
 (0)