Registry / testing / pytest-cache

pytest-cache

JSON →
library1.0pypypiunverified

pytest-cache was an external plugin for pytest that provided mechanisms for caching data across test runs, including options to re-run only last failed tests (`--lf`) or run failed tests first (`--ff`), and a `config.cache` object for plugins to store and retrieve values. Its core functionality was integrated into pytest itself starting around versions 2.8 and 3.8. The last release of the standalone `pytest-cache` plugin was version 1.0 in June 2013, making it effectively abandoned as its features are now part of `pytest` core.

pip install pytest-cache
INSTALL
IMPORT
SIG · PYTEST-CACHE
P
pytest-cache
testingpythonv1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

This quickstart demonstrates how to use the caching mechanisms directly provided by modern pytest, which supersede the `pytest-cache` plugin. It shows how to access the `cache` fixture, and common command-line options for test re-running and cache management.

# The functionality of pytest-cache is now built into pytest. # To access the cache in modern pytest: def test_example_with_cache(cache): # Get a value from the cache, with a default if not found cached_value = cache.get('myplugin/some_key', 'default_value') print(f"Cached value: {cached_value}") # Set a value in the cache cache.set('myplugin/some_key', 'new_value') # To run only last failed tests: # pytest --lf # To run failed tests first, then the rest: # pytest --ff # To clear the cache: # pytest --cache-clear
Debug
Known issues
breakingThe standalone `pytest-cache` plugin is obsolete. Its core functionalities, such as the `cache` fixture and command-line options like `--lf` (last failed) and `--ff` (failed first), were integrated directly into `pytest` starting with `pytest` 2.8 and later refined. Directly installing and using `pytest-cache` with modern `pytest` versions is not recommended and may lead to unexpected behavior or conflicts.
fix
Remove `pytest-cache` from your dependencies. Use `pytest`'s built-in `cache` fixture and command-line options. For example, `from _pytest.cacheprovider import Cache` is an internal import, but the `cache` fixture is the public API.
affects: <= 1.0 (external plugin), >= 2.8 (pytest core integration)
deprecatedThe `pytest-cache` plugin itself has not been updated since June 2013 (version 1.0) and is considered abandoned. All its relevant features are now maintained and provided by the `pytest` core. Relying on this old, external plugin is unnecessary and potentially insecure.
fix
Do not install `pytest-cache`. Ensure your `pytest` installation is up-to-date to benefit from the integrated caching features.
affects: All versions of `pytest-cache`.
gotchaThe cache directory for `pytest` was renamed from `.cache` to `.pytest_cache` to clarify its purpose. If migrating from very old `pytest-cache` setups, be aware of this change. The `.pytest_cache` directory is typically created in the project's root directory and should generally be ignored by version control systems, although `pytest` now often adds a `.gitignore` file within it automatically.
fix
Ensure `.pytest_cache/` is added to your project's `.gitignore` if `pytest` does not automatically create one, to prevent committing cache files. Understand that `pytest` manages this directory for cross-session state.
affects: All versions of `pytest` that use built-in caching (>= 2.8).
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytest_cache'
An outdated project or configuration is attempting to import or depend on the standalone `pytest-cache` plugin, but it is not installed or has been explicitly removed, as its functionality is now integrated into `pytest` core.
fix
Remove the `pytest-cache` dependency from your project's requirements and update any code that explicitly imports it. Use `pytest`'s built-in caching mechanism (e.g., via `request.config.cache`) directly.
unknown option: --lf
The user is attempting to use the `--lf` (last failed) command-line option, but the installed `pytest` version is too old to have this option built-in, and the standalone `pytest-cache` plugin (which originally provided it) is either not installed or not active.
fix
Upgrade `pytest` to a modern version (e.g., `pip install --upgrade pytest`). The `--lf` option has been part of core `pytest` since version 2.8, and `--ff` (failed first) since 3.8.
UserWarning: The pytest-cache plugin is deprecated. Its functionality is now built into pytest.
This warning occurs when the standalone `pytest-cache` plugin is still installed and detected in an environment using a modern `pytest` version, indicating that the plugin is redundant because its features are now part of `pytest` core.
fix
Uninstall the standalone `pytest-cache` plugin (`pip uninstall pytest-cache`). The caching features, including `--lf`, `--ff`, and `request.config.cache`, are available directly through your `pytest` installation.
Upgrade
Version history
1.0latest on PyPI · released Jun 4, 2013
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
pytest-cache — pip install pytest-cache · libregistry