lru_cache in tests

Quite often lru_cache (functools) may wreak havoc in tests as the results might get cached between tests and this is not what we usually expect. Here is a handy fixture that resets all lru_caches for each test:

@pytest.fixture(autouse=True)
def clear_caches():
    import functools
    import gc

    gc.collect()
    wrappers = [
        a for a in gc.get_objects()
        if isinstance(a, functools._lru_cache_wrapper)]

    for wrapper in wrappers:
        wrapper.cache_clear()