Skip to content

Add support for the new pytest_runtest_logfinish hook (pytest 3.4) #266

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
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog/266.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for the ``pytest_runtest_logfinish`` hook which will be released in pytest 3.4.
19 changes: 19 additions & 0 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,25 @@ def test_func(request):
"*1 passed, 1 warnings*",
])

def test_logfinish_hook(self, testdir):
"""Ensure the pytest_runtest_logfinish hook is being properly handled"""
from _pytest import hookspec
if not hasattr(hookspec, 'pytest_runtest_logfinish'):
pytest.skip('test requires pytest_runtest_logfinish hook in pytest (3.4+)')

testdir.makeconftest("""
def pytest_runtest_logfinish():
print('pytest_runtest_logfinish hook called')
""")
testdir.makepyfile("""
def test_func():
pass
""")
result = testdir.runpytest("-n1", "-s")
result.stdout.fnmatch_lines([
"*pytest_runtest_logfinish hook called*",
])


def test_teardownfails_one_function(testdir):
p = testdir.makepyfile("""
Expand Down
5 changes: 5 additions & 0 deletions xdist/dsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ def slave_logstart(self, node, nodeid, location):
self.config.hook.pytest_runtest_logstart(
nodeid=nodeid, location=location)

def slave_logfinish(self, node, nodeid, location):
"""Emitted when a node calls the pytest_runtest_logfinish hook."""
self.config.hook.pytest_runtest_logfinish(
nodeid=nodeid, location=location)

def slave_testreport(self, node, rep):
"""Emitted when a node calls the pytest_runtest_logreport hook."""
rep.node = node
Expand Down
7 changes: 7 additions & 0 deletions xdist/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import sys
import os
import time

import _pytest.hookspec
import pytest


Expand Down Expand Up @@ -93,6 +95,11 @@ def pytest_collection_finish(self, session):
def pytest_runtest_logstart(self, nodeid, location):
self.sendevent("logstart", nodeid=nodeid, location=location)

# the pytest_runtest_logfinish hook was introduced in pytest 3.4
if hasattr(_pytest.hookspec, 'pytest_runtest_logfinish'):
def pytest_runtest_logfinish(self, nodeid, location):
self.sendevent("logfinish", nodeid=nodeid, location=location)

def pytest_runtest_logreport(self, report):
data = serialize_report(report)
data["item_index"] = self.item_index
Expand Down
2 changes: 1 addition & 1 deletion xdist/slavemanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def process_from_remote(self, eventcall): # noqa too complex
self._down = True
self.slaveoutput = kwargs['slaveoutput']
self.notify_inproc("slavefinished", node=self)
elif eventname == "logstart":
elif eventname in ("logstart", "logfinish"):
self.notify_inproc(eventname, node=self, **kwargs)
elif eventname in (
"testreport", "collectreport", "teardownreport"):
Expand Down