Mocking Cache objects
The SDK provides a number of models to help with the testing of extensions that leverage the caching library.
Mocking @cache decorator
Mocking or testing around the cache decorator presents a particularly interesting problem because decorators are
evaluated when the library is imported. In order to solve this a simple mocked decorator cache_mock can be imported
from the sdk and applied to the imports of the extension.
from unittest.mock import patch
from tools.testing.models import cache_mock
with patch('q2_sdk.core.cache.cache', cache_mock):
from TestingExampleHandler.extension import TestingExampleHandler
...
This bypasses cache() decorator by replacing it with one that simple returns the decorated function.