1

I'm trying to test my apps using pytest. The app uses Redis to store a variable. with that variable, the app can determine some action.

here is my couple code to test in app.py

redis_config = {
    "host": "127.0.0.1",
    "port": 6379,
    "db": 0,
    "charset": "utf-8",
    "decode_responses":True
}

save_redis = redis.Redis(**redis_config)

if save_redis.get("token") is None:
    //do something
else :
    //do another thing

the problem was the test completely running with no error but, the rest under IF or else function doesn't cover tested

I've tried in my test_app.py

save_redis = {}
def set(key, val):
    save_redis[key] = val

def get(key):
    return save_redis[key]
    
def delete(key):
    return save_redis.pop(key, None)

@mock.patch('redis.StrictRedis.get', side_effect=get)
@mock.patch('redis.StrictRedis.set', side_effect=set)
@mock.patch('redis.StrictRedis.delete', side_effect=delete)
@mock.patch('requests.post', side_effect=mocked_requests_get)
def test_check_token(self, get_mock, mock_redis_get, mock_redis_set, client):
   //do testing code
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.