diff --git a/changelog/14148.doc.rst b/changelog/14148.doc.rst new file mode 100644 index 00000000000..f20ec671efc --- /dev/null +++ b/changelog/14148.doc.rst @@ -0,0 +1 @@ +The cache how-to example now guards access to ``pytestconfig.cache`` when the ``cacheprovider`` plugin is disabled. diff --git a/doc/en/how-to/cache.rst b/doc/en/how-to/cache.rst index ca345916fc5..0329f44e686 100644 --- a/doc/en/how-to/cache.rst +++ b/doc/en/how-to/cache.rst @@ -214,11 +214,14 @@ across pytest invocations: @pytest.fixture def mydata(pytestconfig): - val = pytestconfig.cache.get("example/value", None) + cache = getattr(pytestconfig, "cache", None) + if cache is None: + pytest.skip("cacheprovider plugin is disabled") + 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