Skip to content

Change docs to use hookwraper instead of __multicall__ #931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions doc/en/example/simple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -534,23 +534,24 @@ case we just write some informations out to a ``failures`` file::
import pytest
import os.path

@pytest.hookimpl(tryfirst=True)
def pytest_runtest_makereport(item, call, __multicall__):
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
rep = __multicall__.execute()
outcome = yield
rep = outcome.get_result()

# we only look at actual failing test calls, not setup/teardown
if rep.when == "call" and rep.failed:
mode = "a" if os.path.exists("failures") else "w"
with open("failures", mode) as f:
# let's also access a fixture for the fun of it
if "tmpdir" in item.funcargs:
if "tmpdir" in item.fixturenames:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im under the impression we want a naming cleanup for pytest 3.x - funcargs is an inaccurate container name now ^^

extra = " (%s)" % item.funcargs["tmpdir"]
else:
extra = ""

f.write(rep.nodeid + extra + "\n")
return rep


if you then have failing tests::

Expand Down Expand Up @@ -606,16 +607,16 @@ here is a little example implemented via a local plugin::

import pytest

@pytest.hookimpl(tryfirst=True)
def pytest_runtest_makereport(item, call, __multicall__):
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
rep = __multicall__.execute()
outcome = yield
rep = outcome.get_result()

# set an report attribute for each phase of a call, which can
# be "setup", "call", "teardown"

setattr(item, "rep_" + rep.when, rep)
return rep


@pytest.fixture
Expand Down Expand Up @@ -742,5 +743,4 @@ over to ``pytest`` instead. For example::
This makes it convenient to execute your tests from within your frozen
application, using standard ``py.test`` command-line options::

$ ./app_main --pytest --verbose --tb=long --junit-xml=results.xml test-suite/
/bin/sh: ./app_main: No such file or directory
./app_main --pytest --verbose --tb=long --junit-xml=results.xml test-suite/