We are using Redisco for our models, and I am writing some tests for our models, however redis keeps filling up, so for each test, more data is added to reddis.
Is there a way to clear Redis for each test, and what are the best practices when testing (using redis and redisco)
– EDIT –
This is the solution I went with in the end, and I want to share this with others who might have the same question
To make sure each test case is running on a clean Redis instance, start each test case by running
redis = Redis()
redis.flushall()
As people have commented below, make sure you don’t run the tests against a production instance of Redis
I would recommend running a second redis instance for testing (eg. on a different port…) so you are also not able to accidentally drop any production data from your redis when running tests.
You could then use custom
BaseTestClasswhich overrides your project’s settings (in thesetUpmethod – you can also emtpy your redis’ dbs there) so that they point to another redis instance (hopefully you’ve defined your redis connections in your project’s settings) and have all your test classes inherit from this base class.