Merge pull request #4558 from hyunchel/fix-incorrect-example-in-cache-doc

Update cache doc with correct example
This commit is contained in:
Bruno Oliveira 2018-12-21 14:33:41 -02:00 committed by GitHub
commit b5cd43bc95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

1
changelog/4558.doc.rst Normal file
View File

@ -0,0 +1 @@
Update cache documentation example to correctly show cache hit and miss.

View File

@ -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