Skip to content

Commit 0181829

Browse files
Merge pull request #266 from nicoddemus/pytest_runtest_logfinish
Add support for the new pytest_runtest_logfinish hook (pytest 3.4)
2 parents 4dc86a1 + 9b767a8 commit 0181829

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

changelog/266.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for the ``pytest_runtest_logfinish`` hook which will be released in pytest 3.4.

testing/acceptance_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,25 @@ def test_func(request):
375375
"*1 passed, 1 warnings*",
376376
])
377377

378+
def test_logfinish_hook(self, testdir):
379+
"""Ensure the pytest_runtest_logfinish hook is being properly handled"""
380+
from _pytest import hookspec
381+
if not hasattr(hookspec, 'pytest_runtest_logfinish'):
382+
pytest.skip('test requires pytest_runtest_logfinish hook in pytest (3.4+)')
383+
384+
testdir.makeconftest("""
385+
def pytest_runtest_logfinish():
386+
print('pytest_runtest_logfinish hook called')
387+
""")
388+
testdir.makepyfile("""
389+
def test_func():
390+
pass
391+
""")
392+
result = testdir.runpytest("-n1", "-s")
393+
result.stdout.fnmatch_lines([
394+
"*pytest_runtest_logfinish hook called*",
395+
])
396+
378397

379398
def test_teardownfails_one_function(testdir):
380399
p = testdir.makepyfile("""

xdist/dsession.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ def slave_logstart(self, node, nodeid, location):
235235
self.config.hook.pytest_runtest_logstart(
236236
nodeid=nodeid, location=location)
237237

238+
def slave_logfinish(self, node, nodeid, location):
239+
"""Emitted when a node calls the pytest_runtest_logfinish hook."""
240+
self.config.hook.pytest_runtest_logfinish(
241+
nodeid=nodeid, location=location)
242+
238243
def slave_testreport(self, node, rep):
239244
"""Emitted when a node calls the pytest_runtest_logreport hook."""
240245
rep.node = node

xdist/remote.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import sys
1010
import os
1111
import time
12+
13+
import _pytest.hookspec
1214
import pytest
1315

1416

@@ -93,6 +95,11 @@ def pytest_collection_finish(self, session):
9395
def pytest_runtest_logstart(self, nodeid, location):
9496
self.sendevent("logstart", nodeid=nodeid, location=location)
9597

98+
# the pytest_runtest_logfinish hook was introduced in pytest 3.4
99+
if hasattr(_pytest.hookspec, 'pytest_runtest_logfinish'):
100+
def pytest_runtest_logfinish(self, nodeid, location):
101+
self.sendevent("logfinish", nodeid=nodeid, location=location)
102+
96103
def pytest_runtest_logreport(self, report):
97104
data = serialize_report(report)
98105
data["item_index"] = self.item_index

xdist/slavemanage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def process_from_remote(self, eventcall): # noqa too complex
304304
self._down = True
305305
self.slaveoutput = kwargs['slaveoutput']
306306
self.notify_inproc("slavefinished", node=self)
307-
elif eventname == "logstart":
307+
elif eventname in ("logstart", "logfinish"):
308308
self.notify_inproc(eventname, node=self, **kwargs)
309309
elif eventname in (
310310
"testreport", "collectreport", "teardownreport"):

0 commit comments

Comments
 (0)