Commits

Matt Bone committed 57c1184

proper flushdb in test setup

Comments (0)

Files changed (2)

         port = metafunc.config.getoption('redis_port')
 
         r = redis.StrictRedis(host=host, port=port, db=0)
-        #r.flushdb()
-        #import pdb; pdb.set_trace()
 
         metafunc.parametrize("redis",
                              [r])
+
+
+def pytest_runtest_setup(item):
+    try:
+        if item.funcargnames.index("redis") == 0:
+            item.funcargs["redis"].flushdb()
+    except ValueError:
+        pass

test_integration.py

 
 
 def test_rpush(redis):
-    redis.flushdb()  # oops, this needs to be in a setup thing not at collection time
     assert redis.rpush("foo", "1") == 1
     assert redis.rpush("foo", "2") == 2
 
     
 
 def test_rpop(redis):
-    redis.flushdb()  # oops, this needs to be in a setup thing not at collection time
     assert redis.rpush("foo", "9", "8", "7") == 3
     assert redis.rpop("foo") == b"7"
     assert redis.rpop("foo") == b"8"
 
 
 def test_sadd(redis):
-    redis.flushdb()  # oops, this needs to be in a setup thing not at collection time
     assert redis.sadd("newset", "1", "2", "2") == 2
     assert redis.scard("newset") == 2
 
 
 def test_sismember(redis):
-    redis.flushdb()  # oops, this needs to be in a setup thing not at collection time
-
     redis.sadd("newset", "1", "2", "3")
     assert redis.sismember("newset", "1") == 1
     assert redis.sismember("newset", "99") == 0
 
 
 def test_hset(redis):
-    redis.flushdb()  # oops, this needs to be in a setup thing not at collection time
-
     assert redis.hset("myhash", "foo", "bar") == 1
     assert redis.hset("myhash", "baz", "biz") == 1
 
 
 
 def test_dbsize(redis):
-    redis.flushdb()  # oops, this needs to be in a setup thing not at collection time
-
     redis.set("foo", "bar")
     redis.set("baz", "biz")
     assert redis.dbsize() == 2