def test_redis_requirement(builtin_pkg, tmpdir): orig_import = __import__ def import_that_fails(name, *args): if name == "redislite": raise ImportError return orig_import(name, *args) with mock.patch("{}.__import__".format(builtin_pkg), side_effect=import_that_fails): directory = tmpdir.mkdir("test_use_redis_store").dirname with pytest.raises(BaseException) as error: global_state.use_redis_store(directory) assert "redislite must be installed" in str(error.value)
def test_use_redis_store(unittest, tmpdir, test_data): pytest.importorskip("redislite") initialize_store(test_data) contents_before = get_store_contents() type_before = get_store_type() directory = tmpdir.mkdir("test_use_redis_store").dirname global_state.use_redis_store(directory) contents_after = get_store_contents() type_after = get_store_type() unittest.assertEqual(contents_before, contents_after) unittest.assertNotEqual(type_before, type_after) global_state.cleanup(data_id="1") unittest.assertNotEqual(contents_after, get_store_contents())