File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 1+ Update cache documentation example to correctly show cache hit and miss.
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments