_pytest.cacheprovider module

merged implementation of the cache provider

the name cache was not chosen to ensure pluggy automatically ignores the external pytest-cache

class Cache(cachedir: pathlib.Path, config: _pytest.config.Config)[source]

Bases: object

_CACHE_PREFIX_DIRS = 'd'
_CACHE_PREFIX_VALUES = 'v'
classmethod for_config(config)[source]
classmethod clear_cache(cachedir: pathlib.Path)[source]

Clears the sub-directories used to hold cached directories and values.

staticmethod cache_dir_from_config(config)[source]
warn(fmt, **args)[source]
makedir(name)[source]

return a directory path object with the given name. If the directory does not yet exist, it will be created. You can use it to manage files likes e. g. store/retrieve database dumps across test sessions.

Parameters

name – must be a string not containing a / separator. Make sure the name contains your plugin or application identifiers to prevent clashes with other cache users.

_getvaluepath(key)[source]
get(key, default)[source]

return cached value for the given key. If no value was yet cached or the value cannot be read, the specified default is returned.

Parameters
  • key – must be a / separated value. Usually the first name is the name of your plugin or your application.

  • default – must be provided in case of a cache-miss or invalid cache values.

set(key, value)[source]

save value for the given key.

Parameters
  • key – must be a / separated value. Usually the first name is the name of your plugin or your application.

  • value – must be of any combination of basic python types, including nested types like e. g. lists of dictionaries.

_ensure_supporting_files()[source]

Create supporting files in the cache dir that are not really part of the cache.

class LFPluginCollWrapper(lfplugin: _pytest.cacheprovider.LFPlugin)[source]

Bases: object

for ... in pytest_make_collect_report(collector) → Generator[source]
class LFPluginCollSkipfiles(lfplugin: _pytest.cacheprovider.LFPlugin)[source]

Bases: object

pytest_make_collect_report(collector) → Optional[_pytest.reports.CollectReport][source]
class LFPlugin(config: _pytest.config.Config)[source]

Bases: object

Plugin which implements the –lf (run last-failing) option

get_last_failed_paths() → Set[pathlib.Path][source]

Returns a set with all Paths()s of the previously failed nodeids.

pytest_report_collectionfinish()[source]
pytest_runtest_logreport(report)[source]
pytest_collectreport(report)[source]
for ... in pytest_collection_modifyitems(config: _pytest.config.Config, items: List[_pytest.nodes.Item]) → Generator[None, None, None][source]
pytest_sessionfinish(session)[source]
class NFPlugin(config)[source]

Bases: object

Plugin which implements the –nf (run new-first) option

for ... in pytest_collection_modifyitems(items: List[_pytest.nodes.Item]) → Generator[None, None, None][source]
_get_increasing_order(items)[source]
pytest_sessionfinish()None[source]
pytest_addoption(parser)[source]
pytest_cmdline_main(config)[source]
pytest_configure(config: _pytest.config.Config)None[source]
cache(request)[source]

Return a cache object that can persist state between testing sessions.

cache.get(key, default) cache.set(key, value)

Keys must be a / separated value, where the first part is usually the name of your plugin or application to avoid clashes with other cache users.

Values can be any object handled by the json stdlib module.

pytest_report_header(config: _pytest.config.Config) → Optional[str][source]

Display cachedir with –cache-show and if non-default.

cacheshow(config, session)[source]