pytest-cache

1.0 · abandoned · verified Tue Apr 14

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.

Warnings

Install

Quickstart

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

view raw JSON →