Skip to content

Commit 3115543

Browse files
author
bwilson
committed
Adding RemoteTarget class to wrap module/function
1 parent 5bb35b0 commit 3115543

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

xdist/newhooks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ def pytest_xdist_rsyncfinish(source, gateways):
3131

3232

3333
@pytest.mark.firstresult
34-
def pytest_xdist_getremotemodule():
35-
""" called when creating remote node"""
34+
def pytest_xdist_getremotetarget():
35+
"""
36+
called to get the remote target.
37+
:return: a workermanager.RemoteTarget
38+
"""
3639

3740

3841
def pytest_configure_node(node):

xdist/workermanage.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import re
55
import threading
6+
import types
67

78
import py
89
import pytest
@@ -205,8 +206,8 @@ class WorkerController(object):
205206

206207
class RemoteHook:
207208
@pytest.mark.trylast
208-
def pytest_xdist_getremotemodule(self):
209-
return xdist.remote
209+
def pytest_xdist_getremotetarget(self):
210+
return RemoteTarget(xdist.remote)
210211

211212
def __init__(self, nodemanager, gateway, config, putevent):
212213
config.pluginmanager.register(self.RemoteHook())
@@ -248,8 +249,8 @@ def setup(self):
248249
basetemp = self.config._tmpdirhandler.getbasetemp()
249250
option_dict["basetemp"] = str(basetemp.join(name))
250251
self.config.hook.pytest_configure_node(node=self)
251-
remote_module = self.config.hook.pytest_xdist_getremotemodule()
252-
self.channel = self.gateway.remote_exec(remote_module)
252+
target, _, target_kwargs = self.config.hook.pytest_xdist_getremotetarget().pack()
253+
self.channel = self.gateway.remote_exec(target, **target_kwargs)
253254
self.channel.send((self.workerinput, args, option_dict))
254255
if self.putevent:
255256
self.channel.setcallback(self.process_from_remote, endmarker=self.ENDMARK)
@@ -359,6 +360,23 @@ def process_from_remote(self, eventcall): # noqa too complex
359360
self.notify_inproc("errordown", node=self, error=excinfo)
360361

361362

363+
class RemoteTarget:
364+
def __init__(self, target, *args, **kwargs):
365+
self._target = target
366+
self._args = args
367+
self._kwargs = kwargs
368+
self.validate()
369+
370+
def validate(self):
371+
# this is based on execnet criteria
372+
assert not self._args, "Positional arguments are not yet supported"
373+
if isinstance(self._target, types.ModuleType):
374+
assert not (self._args or self._kwargs), "Arguments are not used with module targets"
375+
376+
def pack(self):
377+
return self._target, self._args, self._kwargs
378+
379+
362380
def unserialize_report(name, reportdict):
363381
def assembled_report(reportdict):
364382
from _pytest._code.code import (

0 commit comments

Comments
 (0)