I'm using a joblib.Memory
to cache expensive computations when running tests with py.test
. The code I'm using reduces to the following,
from joblib import Memory
memory = Memory(cachedir='/tmp/')
@memory.cache
def expensive_function(x):
return x**2 # some computationally expensive operation here
def test_other_function():
input_ds = expensive_function(x=10)
## run some tests with input_ds
which works fine. I'm aware this could be possibly more elegantly done with tmpdir_factory
fixture but that's beside the point.
The issue I'm having is how to clean the cached files once all the tests run,
- is it possible to share a global variable among all tests (which would contains e.g. a list of path to the cached objects) ?
- is there a mechanism in py.test to call some command once all the tests are run (whether they succeed or not)?