Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the idea behind pytest-cache?

pytest-cache

It seems to be a tool to cache func/args->result pairs and even persist them between testsuite-runs. Which seems like a great idea to speed things up. However I haven't noticed any mention of automatically detecting a change of a function source code and invalidating corresponding cache entries. That seems to defeat the purpose of running the test suite, because the tested code changes are not going to be reflected.

like image 603
user257754 Avatar asked Oct 15 '14 12:10

user257754


People also ask

What happened to pytest-cache?

The default cache directory has been renamed from .cache to .pytest_cache after community feedback that the name .cache did not make it clear that it was used by pytest. According to the docs, pytest-cache was integrated in pytest 2.8, and the plugin provides two command line options to rerun failures from the last pytest invocation:

How do I clear the cache in pytest?

For cleanup (usually not needed), a --cache-clear option allows to remove all cross-session cache contents ahead of a test run. Since pytest version 3.8.1 (2018-09-22) .pytest_cache directory contains its own .gitignore file and is automatically ignored by Git. ( see more)

What is pytest and how to use it?

Pytest is quick and easy to learn. Pytest can choose to run a particular test method or all the test methods of a particular test file based on conditions. Pytest is capable of skipping a few test methods out of all the test methods during test execution. Pytest can be used to test a wide range of applications on API, database and so on.

What are the advantages of using pytest framework?

The advantages of pytest framework are listed below − Pytest is capable of executing multiple test cases simultaneously, thereby reducing the execution duration. Pytest is capable of skipping a test method from a group of test methods during execution.


1 Answers

pytest-cache does two things:

  • offer a mechanism through which other plugins can get/set values via config.cache.get|set. This is used by pytest-pep8 and pytest-flakes for example to store the mtime of the last check to avoid re-checking files all the time.

  • store test failures so that you can run --lf to run only the last failures and --ff to run the last failures first, then the rest of the tests.

The functionality is bound to move to the core with pytest-2.7 (not released as of today) or a subsequent release.

like image 118
hpk42 Avatar answered Oct 06 '22 05:10

hpk42