Removing cached files after a py.test run : <p>I'm using a <code>joblib.Memory</code> to cache expensive computations when running tests with <code>py.test</code>. The code I'm using reduces to the following,</p>

<pre><code>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
</code></pre>

<p>which works fine. I'm aware this could be possibly more elegantly done with <a href="http://docs.pytest.org/en/latest/tmpdir.html" rel="noreferrer"><code>tmpdir_factory</code></a> fixture but that's beside the point.</p>

<p>The issue I'm having is how to clean the cached files once all the tests run,</p>

<ul>
<li>is it possible to share a global variable among all tests (which would contains e.g. a list of path to the cached objects) ?</li>
<li>is there a mechanism in py.test to call some command once all the tests are run (whether they succeed or not)?</li>
</ul>
