pytest-antilru
raw JSON → 2.0.0 verified Fri May 01 auth: no python
Bust functools.lru_cache when running pytest to avoid test pollution. Version 2.0.0 dropped Python 2.7 and 3.5–3.7, added Python 3.10–3.13 support, and introduced the 'lru_cache_disabled' config option. Maintained on GitHub.
pip install pytest-antilru Common errors
error ModuleNotFoundError: No module named 'pytest_antilru' ↓
cause Explicitly importing pytest_antilru when not needed. The plugin is loaded automatically.
fix
Remove
import pytest_antilru from your conftest or test files; it auto-discovers via entrypoints. error AttributeError: 'function' object has no attribute 'cache_clear' ↓
cause Using the plugin on functions decorated with `@lru_cache` (without parentheses) before Python 3.8. The plugin relies on the wrapper object.
fix
Upgrade to Python >=3.8 or use
@lru_cache() with parentheses. Warnings
breaking Version 2.0 drops Python 2.7, 3.5, 3.6, 3.7. Only Python >=3.8 supported. ↓
fix Upgrade to Python >=3.8 and use v2.0.0.
deprecated The old entrypoint name 'pytest-antilru' was incorrect in v1.0.x; fixed in v1.1.1. If you manually configured entrypoints, update. ↓
fix Ensure pytest-antilru is installed; no manual entrypoint config needed.
gotcha If you use `lru_cache` with `maxsize=None` (or as a plain decorator), the cache is still busted. This is intended but may surprise users who expect unbounded caches to persist. ↓
fix No fix needed; it's by design. Use `lru_cache_disabled` config option in v2 to selectively skip modules.
gotcha The plugin does not bust caches for `functools.cache` (Python 3.9+) or `functools.cached_property`. Only `lru_cache` unwrapped and wrapped with parentheses are handled. ↓
fix Manually call `.cache_clear()` on `functools.cache` or `cached_property` if needed.
Imports
- pytest_antilru wrong
import pytest_antilru # no wrong pattern, plugin auto-loadscorrectimport pytest_antilru
Quickstart
# Install: pip install pytest-antilru
# Then just run pytest normally; lru_cache is busted per test session.
def test_example():
# lru_cache will be cleared before each test
from mymodule import cached_func
assert cached_func(1) == cached_func(1) # still works within test