Skip to content

Commit d753e53

Browse files
authored
Merge pull request #374 from illiterati1/add_remote_hook
Add a hook to allow overriding the remote module that's executed by e…
2 parents bc44fea + 81309e8 commit d753e53

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

changelog/374.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The new ``pytest_xdist_getremotemodule`` hook allows overriding the module run on remote nodes.
File renamed without changes.

xdist/newhooks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ def pytest_xdist_rsyncfinish(source, gateways):
3030
""" called after rsyncing a directory to remote gateways takes place. """
3131

3232

33+
@pytest.mark.firstresult
34+
def pytest_xdist_getremotemodule():
35+
""" called when creating remote node"""
36+
37+
3338
def pytest_configure_node(node):
3439
""" configure node information before it gets instantiated. """
3540

xdist/remote.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import time
1212

13+
import py
1314
import _pytest.hookspec
1415
import pytest
1516
from execnet.gateway_base import dumps, DumpError
@@ -261,8 +262,6 @@ def remote_initconfig(option_dict, args):
261262

262263

263264
if __name__ == "__channelexec__":
264-
import py
265-
266265
channel = channel # noqa
267266
workerinput, args, option_dict, change_sys_path = channel.receive()
268267

xdist/workermanage.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,13 @@ def make_reltoroot(roots, args):
204204
class WorkerController(object):
205205
ENDMARK = -1
206206

207+
class RemoteHook:
208+
@pytest.mark.trylast
209+
def pytest_xdist_getremotemodule(self):
210+
return xdist.remote
211+
207212
def __init__(self, nodemanager, gateway, config, putevent):
213+
config.pluginmanager.register(self.RemoteHook())
208214
self.nodemanager = nodemanager
209215
self.putevent = putevent
210216
self.gateway = gateway
@@ -244,10 +250,13 @@ def setup(self):
244250
basetemp = self.config._tmpdirhandler.getbasetemp()
245251
option_dict["basetemp"] = str(basetemp.join(name))
246252
self.config.hook.pytest_configure_node(node=self)
247-
self.channel = self.gateway.remote_exec(xdist.remote)
253+
254+
remote_module = self.config.hook.pytest_xdist_getremotemodule()
255+
self.channel = self.gateway.remote_exec(remote_module)
248256
# change sys.path only for remote workers
249257
change_sys_path = not self.gateway.spec.popen
250258
self.channel.send((self.workerinput, args, option_dict, change_sys_path))
259+
251260
if self.putevent:
252261
self.channel.setcallback(self.process_from_remote, endmarker=self.ENDMARK)
253262

0 commit comments

Comments
 (0)