Skip to content

Commit f9156e3

Browse files
authored
fixed error message for cache proxy creation (#795)
1 parent a6a131e commit f9156e3

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

aiocache/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Cache:
6060
MEMCACHED = AIOCACHE_CACHES.get("memcached")
6161

6262
def __new__(cls, cache_class=MEMORY, **kwargs):
63-
if not issubclass(cache_class, BaseCache):
63+
if not (cache_class and issubclass(cache_class, BaseCache)):
6464
raise InvalidCacheType(
6565
"Invalid cache type, you can only use {}".format(list(AIOCACHE_CACHES.keys()))
6666
)

tests/ut/test_factory.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ async def test_new(self, cache_type):
7474
def test_new_defaults_to_memory(self):
7575
assert isinstance(Cache(), Cache.MEMORY)
7676

77-
def test_new_invalid_cache_raises(self):
77+
@pytest.mark.parametrize("cache_type", (None, object))
78+
def test_new_invalid_cache_raises(self, cache_type):
7879
with pytest.raises(InvalidCacheType) as e:
79-
Cache(object)
80+
Cache(cache_type)
8081
assert str(e.value) == "Invalid cache type, you can only use {}".format(
8182
list(AIOCACHE_CACHES.keys())
8283
)

0 commit comments

Comments
 (0)