ipwnponies / pytest-antilru

Bust functools.lru_cache when running pytest to avoid test pollution
MIT License
20 stars 3 forks source link

Feature request: support for functools.cache #26

Closed ronkorving closed 1 year ago

ronkorving commented 1 year ago

I use @cache in places, and would love to use this plugin to clear those caches between tests. Is that something that has a place in this project?

ronkorving commented 1 year ago

Okay, nevermind. It already seems to do the trick. I guess functools.cache uses lrucache under the hood? :)

ipwnponies commented 1 year ago

https://github.com/python/cpython/blob/3.9/Lib/functools.py#L652

def cache(user_function, /):
    'Simple lightweight unbounded cache.  Sometimes called "memoize".'
    return lru_cache(maxsize=None)(user_function)

It's basically functools.partial() on lru_cache 😄