pytest demo
tests.py
python
import unittest
from redis import StrictRedis
from common.config import REDIS_HOST, REDIS_PORT, REDIS_TOKEN_DB, REDIS_PASSWORD
class TestRedisFunctionality(unittest.TestCase):
def setUp(self):
self.app_redis = StrictRedis(
host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWORD, db=REDIS_TOKEN_DB, decode_responses=True
)
def tearDown(self):
self.app_redis.connection_pool.disconnect()
def test_set_get_delete(self):
key, value = "test_key", "test_value"
self.assertTrue(self.app_redis.set(key, value))
self.assertEqual(self.app_redis.get(key), value)
self.assertEqual(self.app_redis.delete(key), 1)
self.assertIsNone(self.app_redis.get(key))
if __name__ == '__main__':
unittest.main()
run
shell
pytest tests.py