diff --git a/changelog/374.feature.rst b/changelog/374.feature.rst new file mode 100644 index 0000000..d0c6c88 --- /dev/null +++ b/changelog/374.feature.rst @@ -0,0 +1 @@ +The new ``pytest_xdist_getremotemodule`` hook allows overriding the module run on remote nodes. diff --git a/changelog/415.feature b/changelog/415.feature.rst similarity index 100% rename from changelog/415.feature rename to changelog/415.feature.rst diff --git a/xdist/newhooks.py b/xdist/newhooks.py index 7d8007f..f389192 100644 --- a/xdist/newhooks.py +++ b/xdist/newhooks.py @@ -30,6 +30,11 @@ def pytest_xdist_rsyncfinish(source, gateways): """ called after rsyncing a directory to remote gateways takes place. """ +@pytest.mark.firstresult +def pytest_xdist_getremotemodule(): + """ called when creating remote node""" + + def pytest_configure_node(node): """ configure node information before it gets instantiated. """ diff --git a/xdist/remote.py b/xdist/remote.py index 1ea8898..c492f9e 100644 --- a/xdist/remote.py +++ b/xdist/remote.py @@ -10,6 +10,7 @@ import sys import os import time +import py import _pytest.hookspec import pytest from execnet.gateway_base import dumps, DumpError @@ -261,8 +262,6 @@ def remote_initconfig(option_dict, args): if __name__ == "__channelexec__": - import py - channel = channel # noqa workerinput, args, option_dict, change_sys_path = channel.receive() diff --git a/xdist/workermanage.py b/xdist/workermanage.py index 75465d0..d08478a 100644 --- a/xdist/workermanage.py +++ b/xdist/workermanage.py @@ -204,7 +204,13 @@ def make_reltoroot(roots, args): class WorkerController(object): ENDMARK = -1 + class RemoteHook: + @pytest.mark.trylast + def pytest_xdist_getremotemodule(self): + return xdist.remote + def __init__(self, nodemanager, gateway, config, putevent): + config.pluginmanager.register(self.RemoteHook()) self.nodemanager = nodemanager self.putevent = putevent self.gateway = gateway @@ -244,10 +250,13 @@ class WorkerController(object): basetemp = self.config._tmpdirhandler.getbasetemp() option_dict["basetemp"] = str(basetemp.join(name)) self.config.hook.pytest_configure_node(node=self) - self.channel = self.gateway.remote_exec(xdist.remote) + + remote_module = self.config.hook.pytest_xdist_getremotemodule() + self.channel = self.gateway.remote_exec(remote_module) # change sys.path only for remote workers change_sys_path = not self.gateway.spec.popen self.channel.send((self.workerinput, args, option_dict, change_sys_path)) + if self.putevent: self.channel.setcallback(self.process_from_remote, endmarker=self.ENDMARK)