From ece01b0f56dcb5824dc36c9da726a1fe98d3906f Mon Sep 17 00:00:00 2001 From: Hyunchel Kim Date: Fri, 21 Dec 2018 04:37:22 +0000 Subject: [PATCH] Update cache documentation example to correctly show cache hit and miss --- changelog/4558.doc.rst | 1 + doc/en/cache.rst | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 changelog/4558.doc.rst diff --git a/changelog/4558.doc.rst b/changelog/4558.doc.rst new file mode 100644 index 000000000..09dc5b863 --- /dev/null +++ b/changelog/4558.doc.rst @@ -0,0 +1 @@ +Update cache documentation example to correctly show cache hit and miss. diff --git a/doc/en/cache.rst b/doc/en/cache.rst index 914c36fed..a0fa72db1 100644 --- a/doc/en/cache.rst +++ b/doc/en/cache.rst @@ -185,11 +185,14 @@ across pytest invocations:: import pytest import time + def expensive_computation(): + print("running expensive computation...") + @pytest.fixture def mydata(request): val = request.config.cache.get("example/value", None) if val is None: - time.sleep(9*0.6) # expensive computation :) + expensive_computation() val = 42 request.config.cache.set("example/value", val) return val @@ -197,8 +200,7 @@ across pytest invocations:: def test_function(mydata): assert mydata == 23 -If you run this command once, it will take a while because -of the sleep: +If you run this command for the first time, you can see the print statement: .. code-block:: pytest @@ -217,7 +219,7 @@ of the sleep: 1 failed in 0.12 seconds If you run it a second time the value will be retrieved from -the cache and this will be quick: +the cache and nothing will be printed: .. code-block:: pytest