Skip to content

Commit ece01b0

Browse files
committed
Update cache documentation example to correctly show cache hit and miss
1 parent 0a40ae4 commit ece01b0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

changelog/4558.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update cache documentation example to correctly show cache hit and miss.

doc/en/cache.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,22 @@ across pytest invocations::
185185
import pytest
186186
import time
187187

188+
def expensive_computation():
189+
print("running expensive computation...")
190+
188191
@pytest.fixture
189192
def mydata(request):
190193
val = request.config.cache.get("example/value", None)
191194
if val is None:
192-
time.sleep(9*0.6) # expensive computation :)
195+
expensive_computation()
193196
val = 42
194197
request.config.cache.set("example/value", val)
195198
return val
196199

197200
def test_function(mydata):
198201
assert mydata == 23
199202

200-
If you run this command once, it will take a while because
201-
of the sleep:
203+
If you run this command for the first time, you can see the print statement:
202204

203205
.. code-block:: pytest
204206
@@ -217,7 +219,7 @@ of the sleep:
217219
1 failed in 0.12 seconds
218220
219221
If you run it a second time the value will be retrieved from
220-
the cache and this will be quick:
222+
the cache and nothing will be printed:
221223

222224
.. code-block:: pytest
223225

0 commit comments

Comments
 (0)