serhii.net

In the middle of the desert you can say anything you want

27 Nov 2023

pytest and lru_cache

I have a pytest of a function that uses python @lru_cache:

    cacheinfo = gbif_get_taxonomy_id.cache_info()
    assert cacheinfo.hits == 1
    assert cacheinfo.misses == 2

LRU cache gets preserved among test runs, breaking independence and making such bits fail.

Enter pytest-antilru · PyPI which resets the LRU cache between test runs. Installing it as a python package is all there’s to ite.

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus