Registry / testing / pytest-antilru

pytest-antilru

JSON →
library2.0.1pypypi✓ verified 86d ago

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
INSTALL
IMPORT
SIG · PYTEST-ANTILRU
P
pytest-antilru
testingpythonv2.0.1
Install
2.7s avg
Import
Disk
29MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 30.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.000s · 31MB
29MB installed
● package 29MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest_antilru
import pytest_antilru
import pytest_antilru # no wrong pattern, plugin auto-loads
The plugin is auto-detected by pytest via entrypoints; no explicit import needed.

After installation, `pytest-antilru` automatically busts all `functools.lru_cache` caches between tests to prevent state leakage.

# 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
Debug
Known issues
breakingVersion 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.
affects: <2.0.0
deprecatedThe 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.
affects: >=1.0.0, <1.1.1
gotchaIf 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.
affects: all
gotchaThe 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.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytest_antilru'
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.
AttributeError: 'function' object has no attribute 'cache_clear'
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.
Upgrade
Version history
2.0.1latest on PyPI · released May 3, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Resources
pytest-antilru — pip install pytest-antilru · libregistry