Merge pull request #4558 from hyunchel/fix-incorrect-example-in-cache-doc
Update cache doc with correct example
This commit is contained in:
commit
b5cd43bc95
|
@ -0,0 +1 @@
|
|||
Update cache documentation example to correctly show cache hit and miss.
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue