In my implementation script I have a line which logs a metric:
from datadog import statsd
def some_function:
statsd.increment('some_metric')
From my test script, I assert that statsd.increment() is called by mocking out the datadog module:
datadog = Mock()
sys.modules['datadog'] = datadog
def test():
some_function()
datadog.statsd.increment.assert_called()
This works fine and passes. But as soon as I add ANOTHER script which calls some_function() without mocking datadog, that script runs beforehand and loads the real datadog module into the cache. The above test then fails because some_function() is no longer using the mock datadog, it uses the real (cached) datadog.
How can I address this? Is it possible to remove the module from the cache?