Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/14148.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Documented a safe ``pytestconfig.cache`` access pattern when the
``cacheprovider`` plugin is disabled.
11 changes: 9 additions & 2 deletions doc/en/how-to/cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,18 @@ across pytest invocations:

@pytest.fixture
def mydata(pytestconfig):
val = pytestconfig.cache.get("example/value", None)
cache = getattr(pytestconfig, "cache", None)
if cache is None:
# pytestconfig not having the cache attribute means the
# cache plugin is disabled.
expensive_computation()
return 42

val = cache.get("example/value", None)
if val is None:
expensive_computation()
val = 42
pytestconfig.cache.set("example/value", val)
cache.set("example/value", val)
return val


Expand Down