#234 Fix flake 8 and fix comments

This commit is contained in:
feuillemorte
2018-01-17 23:34:39 +03:00
parent 9a5a81962c
commit b04703b6ba
7 changed files with 23 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
import py import py
import pytest import pytest
from xdist.workermanage import workerController, unserialize_report from xdist.workermanage import WorkerController, unserialize_report
from xdist.remote import serialize_report from xdist.remote import serialize_report
import execnet import execnet
import marshal import marshal
@@ -26,7 +26,7 @@ class EventCall:
return "<EventCall %s(**%s)>" % (self.name, self.kwargs) return "<EventCall %s(**%s)>" % (self.name, self.kwargs)
class workerSetup: class WorkerSetup:
use_callback = False use_callback = False
def __init__(self, request, testdir): def __init__(self, request, testdir):
@@ -44,8 +44,8 @@ class workerSetup:
class DummyMananger: class DummyMananger:
specs = [0, 1] specs = [0, 1]
self.slp = workerController(DummyMananger, self.gateway, config, self.slp = WorkerController(DummyMananger, self.gateway, config,
putevent) putevent)
self.request.addfinalizer(self.slp.ensure_teardown) self.request.addfinalizer(self.slp.ensure_teardown)
self.slp.setup() self.slp.setup()
@@ -66,7 +66,7 @@ class workerSetup:
@pytest.fixture @pytest.fixture
def worker(request, testdir): def worker(request, testdir):
return workerSetup(request, testdir) return WorkerSetup(request, testdir)
@pytest.mark.xfail(reason='#59') @pytest.mark.xfail(reason='#59')
@@ -243,7 +243,7 @@ class TestReportSerialization:
assert newrep.longrepr == str(rep.longrepr) assert newrep.longrepr == str(rep.longrepr)
class TestworkerInteractor: class TestWorkerInteractor:
def test_basic_collect_and_runtests(self, worker): def test_basic_collect_and_runtests(self, worker):
worker.testdir.makepyfile(""" worker.testdir.makepyfile("""
def test_func(): def test_func():

View File

@@ -40,7 +40,7 @@ def workercontroller(monkeypatch):
def setup(self): def setup(self):
pass pass
monkeypatch.setattr(workermanage, 'workerController', MockController) monkeypatch.setattr(workermanage, 'WorkerController', MockController)
return MockController return MockController

View File

@@ -182,7 +182,7 @@ class DSession:
self._active_nodes.remove(node) self._active_nodes.remove(node)
def worker_errordown(self, node, error): def worker_errordown(self, node, error):
"""Emitted by the workerController when a node dies.""" """Emitted by the WorkerController when a node dies."""
self.config.hook.pytest_testnodedown(node=node, error=error) self.config.hook.pytest_testnodedown(node=node, error=error)
try: try:
crashitem = self.sched.remove_node(node) crashitem = self.sched.remove_node(node)

View File

@@ -153,11 +153,11 @@ def init_worker_session(channel, args, option_dict):
from _pytest.config import Config from _pytest.config import Config
config = Config.fromdictargs(option_dict, list(args)) config = Config.fromdictargs(option_dict, list(args))
config.args = args config.args = args
from xdist.looponfail import workerFailSession from xdist.looponfail import WorkerFailSession
workerFailSession(config, channel).main() WorkerFailSession(config, channel).main()
class workerFailSession: class WorkerFailSession:
def __init__(self, config, channel): def __init__(self, config, channel):
self.config = config self.config = config
self.channel = channel self.channel = channel

View File

@@ -30,7 +30,8 @@ def pytest_addoption(parser):
dest="maxworkerrestart", dest="maxworkerrestart",
help="maximum number of workers that can be restarted " help="maximum number of workers that can be restarted "
"when crashed (set to zero to disable this feature)\n" "when crashed (set to zero to disable this feature)\n"
"'--max-slave-restart' option is deprecated and will be removed in a future release") "'--max-slave-restart' option is deprecated and will be removed in "
"a future release")
group.addoption( group.addoption(
'--dist', metavar="distmode", '--dist', metavar="distmode",
action="store", choices=['each', 'load', 'loadscope', 'loadfile', 'no'], action="store", choices=['each', 'load', 'loadscope', 'loadfile', 'no'],

View File

@@ -14,7 +14,7 @@ import _pytest.hookspec
import pytest import pytest
class workerInteractor: class WorkerInteractor:
def __init__(self, config, channel): def __init__(self, config, channel):
self.config = config self.config = config
self.workerid = config.workerinput.get('workerid', "?") self.workerid = config.workerinput.get('workerid', "?")
@@ -198,5 +198,8 @@ if __name__ == '__channelexec__':
config = remote_initconfig(option_dict, args) config = remote_initconfig(option_dict, args)
config.workerinput = workerinput config.workerinput = workerinput
config.workeroutput = {} config.workeroutput = {}
interactor = workerInteractor(config, channel) # TODO: deprecated name, backward compatibility only. Remove it in future
config.slaveinput = config.workerinput
config.slaveoutput = config.workeroutput
interactor = WorkerInteractor(config, channel)
config.hook.pytest_cmdline_main(config=config) config.hook.pytest_cmdline_main(config=config)

View File

@@ -68,7 +68,7 @@ class NodeManager(object):
gw = self.group.makegateway(spec) gw = self.group.makegateway(spec)
self.config.hook.pytest_xdist_newgateway(gateway=gw) self.config.hook.pytest_xdist_newgateway(gateway=gw)
self.rsync_roots(gw) self.rsync_roots(gw)
node = workerController(self, gw, self.config, putevent) node = WorkerController(self, gw, self.config, putevent)
gw.node = node # keep the node alive gw.node = node # keep the node alive
node.setup() node.setup()
self.trace("started node %r" % node) self.trace("started node %r" % node)
@@ -201,7 +201,7 @@ def make_reltoroot(roots, args):
return result return result
class workerController(object): class WorkerController(object):
ENDMARK = -1 ENDMARK = -1
def __init__(self, nodemanager, gateway, config, putevent): def __init__(self, nodemanager, gateway, config, putevent):
@@ -210,7 +210,9 @@ class workerController(object):
self.gateway = gateway self.gateway = gateway
self.config = config self.config = config
self.workerinput = {'workerid': gateway.id, self.workerinput = {'workerid': gateway.id,
'workercount': len(nodemanager.specs)} 'workercount': len(nodemanager.specs)}
# TODO: deprecated name, backward compatibility only. Remove it in future
self.slaveinput = self.workerinput
self._down = False self._down = False
self._shutdown_sent = False self._shutdown_sent = False
self.log = py.log.Producer("workerctl-%s" % gateway.id) self.log = py.log.Producer("workerctl-%s" % gateway.id)