@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 AssertionError: assert 'key1' in [] RedisKeyValue = RedisLocal = keys = [] redis = redisl = tests/test_redis.py:39: AssertionError