Mention to use stash in the doc
This commit is contained in:
parent
99dfc19fe6
commit
83ab8be5f6
|
@ -895,6 +895,8 @@ here is a little example implemented via a local plugin:
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
your_unique_key = StashKey[Dict[str, bool]]()
|
||||||
|
|
||||||
|
|
||||||
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||||
def pytest_runtest_makereport(item, call):
|
def pytest_runtest_makereport(item, call):
|
||||||
|
@ -902,10 +904,12 @@ here is a little example implemented via a local plugin:
|
||||||
outcome = yield
|
outcome = yield
|
||||||
rep = outcome.get_result()
|
rep = outcome.get_result()
|
||||||
|
|
||||||
# set a report attribute for each phase of a call, which can
|
# store test results for each phase of a call, which can
|
||||||
# be "setup", "call", "teardown"
|
# be "setup", "call", "teardown"
|
||||||
|
if your_unique_key not in item.stash:
|
||||||
setattr(item, "rep_" + rep.when, rep)
|
item.stash[your_unique_key] = {rep.when: rep.passed}
|
||||||
|
else:
|
||||||
|
item.stash[your_unique_key][rep.when] = rep.passed
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -913,11 +917,13 @@ here is a little example implemented via a local plugin:
|
||||||
yield
|
yield
|
||||||
# request.node is an "item" because we use the default
|
# request.node is an "item" because we use the default
|
||||||
# "function" scope
|
# "function" scope
|
||||||
if request.node.rep_setup.failed:
|
result = request.node.stash[your_unique_key]
|
||||||
|
if not result.get("setup", False):
|
||||||
print("setting up a test failed!", request.node.nodeid)
|
print("setting up a test failed!", request.node.nodeid)
|
||||||
elif request.node.rep_setup.passed:
|
elif not result.get("call", False):
|
||||||
if request.node.rep_call.failed:
|
|
||||||
print("executing test failed", request.node.nodeid)
|
print("executing test failed", request.node.nodeid)
|
||||||
|
elif not result("teardown", False):
|
||||||
|
print("tear down test failed", request.node.nodeid)
|
||||||
|
|
||||||
|
|
||||||
if you then have failing tests:
|
if you then have failing tests:
|
||||||
|
|
Loading…
Reference in New Issue