@pytest.mark.unit def test_redis_context_manager(): from rtrader.utils.redis import RedisKeyValue, RedisLocal with RedisKeyValue(RedisLocal(), "keys", []) as redis: redis.value.append("key1") redis.value.append("key2") print(redis.value) redisl = RedisLocal() keys = redisl.load("keys") > assert "key1" in keys ^^^^^^^^^^^^^^ E TypeError: argument of type 'NoneType' is not iterable RedisKeyValue = RedisLocal = keys = None redis = redisl = tests/test_redis.py:42: TypeError