prepare #592: replace master with controller where we can
This commit is contained in:
15
README.rst
15
README.rst
@@ -285,7 +285,18 @@ Since version 2.0, the following functions are also available in the ``xdist`` m
|
||||
"""
|
||||
|
||||
def is_xdist_master(request_or_session) -> bool:
|
||||
"""Return `True` if this is the xdist master, `False` otherwise
|
||||
"""Return `True` if this is the xdist controller, `False` otherwise
|
||||
|
||||
Note: this method also returns `False` when distribution has not been
|
||||
activated at all.
|
||||
|
||||
deprecated alias for is_xdist_controller
|
||||
|
||||
:param request_or_session: the `pytest` `request` or `session` object
|
||||
"""
|
||||
|
||||
def is_xdist_controller(request_or_session) -> bool:
|
||||
"""Return `True` if this is the xdist controller, `False` otherwise
|
||||
|
||||
Note: this method also returns `False` when distribution has not been
|
||||
activated at all.
|
||||
@@ -295,7 +306,7 @@ Since version 2.0, the following functions are also available in the ``xdist`` m
|
||||
|
||||
def get_xdist_worker_id(request_or_session) -> str:
|
||||
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
|
||||
if running on the 'master' node.
|
||||
if running on the controller node.
|
||||
|
||||
If not distributing tests (for example passing `-n0` or not passing `-n` at all) also return 'master'.
|
||||
|
||||
|
||||
1
changelog/592.trivial.rst
Normal file
1
changelog/592.trivial.rst
Normal file
@@ -0,0 +1 @@
|
||||
Replace master with controller where ever possible.
|
||||
@@ -1,4 +1,15 @@
|
||||
from xdist.plugin import is_xdist_worker, is_xdist_master, get_xdist_worker_id
|
||||
from xdist.plugin import (
|
||||
is_xdist_worker,
|
||||
is_xdist_master,
|
||||
get_xdist_worker_id,
|
||||
is_xdist_controller,
|
||||
)
|
||||
from xdist._version import version as __version__
|
||||
|
||||
__all__ = ["__version__", "is_xdist_worker", "is_xdist_master", "get_xdist_worker_id"]
|
||||
__all__ = [
|
||||
"__version__",
|
||||
"is_xdist_worker",
|
||||
"is_xdist_master",
|
||||
"is_xdist_controller",
|
||||
"get_xdist_worker_id",
|
||||
]
|
||||
|
||||
@@ -87,7 +87,7 @@ class DSession:
|
||||
self._session = None
|
||||
|
||||
def pytest_collection(self):
|
||||
# prohibit collection of test items in master process
|
||||
# prohibit collection of test items in controller process
|
||||
return True
|
||||
|
||||
@pytest.mark.trylast
|
||||
@@ -240,7 +240,7 @@ class DSession:
|
||||
return
|
||||
self.config.hook.pytest_xdist_node_collection_finished(node=node, ids=ids)
|
||||
# tell session which items were effectively collected otherwise
|
||||
# the master node will finish the session with EXIT_NOTESTSCOLLECTED
|
||||
# the controller node will finish the session with EXIT_NOTESTSCOLLECTED
|
||||
self._session.testscollected = len(ids)
|
||||
self.sched.add_node_collection(node, ids)
|
||||
if self.terminal:
|
||||
|
||||
@@ -48,7 +48,7 @@ def pytest_testnodedown(node, error):
|
||||
|
||||
|
||||
def pytest_xdist_node_collection_finished(node, ids):
|
||||
"""called by the master node when a node finishes collecting.
|
||||
"""called by the controller node when a worker node finishes collecting.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
@@ -227,8 +227,8 @@ def is_xdist_worker(request_or_session) -> bool:
|
||||
return hasattr(request_or_session.config, "workerinput")
|
||||
|
||||
|
||||
def is_xdist_master(request_or_session) -> bool:
|
||||
"""Return `True` if this is the xdist master, `False` otherwise
|
||||
def is_xdist_controller(request_or_session) -> bool:
|
||||
"""Return `True` if this is the xdist controller, `False` otherwise
|
||||
|
||||
Note: this method also returns `False` when distribution has not been
|
||||
activated at all.
|
||||
@@ -241,9 +241,13 @@ def is_xdist_master(request_or_session) -> bool:
|
||||
)
|
||||
|
||||
|
||||
# ALIAS: todo, deprecate
|
||||
is_xdist_master = is_xdist_controller
|
||||
|
||||
|
||||
def get_xdist_worker_id(request_or_session) -> str:
|
||||
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
|
||||
if running on the 'master' node.
|
||||
if running on the controller node.
|
||||
|
||||
If not distributing tests (for example passing `-n0` or not passing `-n` at all)
|
||||
also return 'master'.
|
||||
@@ -253,6 +257,7 @@ def get_xdist_worker_id(request_or_session) -> str:
|
||||
if hasattr(request_or_session.config, "workerinput"):
|
||||
return request_or_session.config.workerinput["workerid"]
|
||||
else:
|
||||
# TODO: remove "master", ideally for a None
|
||||
return "master"
|
||||
|
||||
|
||||
@@ -261,6 +266,7 @@ def worker_id(request):
|
||||
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
|
||||
if running on the master node.
|
||||
"""
|
||||
# TODO: remove "master", ideally for a None
|
||||
return get_xdist_worker_id(request)
|
||||
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ class WorkerInteractor:
|
||||
self.sendevent("testreport", data=data)
|
||||
|
||||
def pytest_collectreport(self, report):
|
||||
# send only reports that have not passed to master as optimization (#330)
|
||||
# send only reports that have not passed to controller as optimization (#330)
|
||||
if not report.passed:
|
||||
data = self.config.hook.pytest_report_to_serializable(
|
||||
config=self.config, report=report
|
||||
@@ -139,7 +139,7 @@ def serialize_warning_message(warning_message):
|
||||
message_class_name = type(warning_message.message).__name__
|
||||
message_str = str(warning_message.message)
|
||||
# check now if we can serialize the warning arguments (#349)
|
||||
# if not, we will just use the exception message on the master node
|
||||
# if not, we will just use the exception message on the controller node
|
||||
try:
|
||||
dumps(warning_message.message.args)
|
||||
except DumpError:
|
||||
|
||||
@@ -244,7 +244,7 @@ class TestDistribution:
|
||||
def test_data_exchange(self, testdir):
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
# This hook only called on master.
|
||||
# This hook only called on the controlling process.
|
||||
def pytest_configure_node(node):
|
||||
node.workerinput['a'] = 42
|
||||
node.workerinput['b'] = 7
|
||||
@@ -257,7 +257,7 @@ class TestDistribution:
|
||||
r = a + b
|
||||
config.workeroutput['r'] = r
|
||||
|
||||
# This hook only called on master.
|
||||
# This hook only called on the controlling process.
|
||||
def pytest_testnodedown(node, error):
|
||||
node.config.calc_result = node.workeroutput['r']
|
||||
|
||||
@@ -289,7 +289,7 @@ class TestDistribution:
|
||||
# on the worker
|
||||
if hasattr(session.config, 'workeroutput'):
|
||||
session.config.workeroutput['s2'] = 42
|
||||
# on the master
|
||||
# on the controller
|
||||
def pytest_testnodedown(node, error):
|
||||
assert node.workeroutput['s2'] == 42
|
||||
print ("s2call-finished")
|
||||
@@ -503,7 +503,7 @@ def test_session_hooks(testdir):
|
||||
if hasattr(session.config, 'workerinput'):
|
||||
name = "worker"
|
||||
else:
|
||||
name = "master"
|
||||
name = "controller"
|
||||
with open(name, "w") as f:
|
||||
f.write("xy")
|
||||
# let's fail on the worker
|
||||
@@ -524,12 +524,12 @@ def test_session_hooks(testdir):
|
||||
d = result.parseoutcomes()
|
||||
assert d["passed"] == 1
|
||||
assert testdir.tmpdir.join("worker").check()
|
||||
assert testdir.tmpdir.join("master").check()
|
||||
assert testdir.tmpdir.join("controller").check()
|
||||
|
||||
|
||||
def test_session_testscollected(testdir):
|
||||
"""
|
||||
Make sure master node is updating the session object with the number
|
||||
Make sure controller node is updating the session object with the number
|
||||
of tests collected from the workers.
|
||||
"""
|
||||
testdir.makepyfile(
|
||||
@@ -574,7 +574,7 @@ def test_fixture_teardown_failure(testdir):
|
||||
|
||||
|
||||
def test_config_initialization(testdir, monkeypatch, pytestconfig):
|
||||
"""Ensure workers and master are initialized consistently. Integration test for #445"""
|
||||
"""Ensure workers and controller are initialized consistently. Integration test for #445"""
|
||||
testdir.makepyfile(
|
||||
**{
|
||||
"dir_a/test_foo.py": """
|
||||
@@ -1138,7 +1138,7 @@ def test_internal_error_with_maxfail(testdir):
|
||||
assert "INTERNALERROR" not in result.stderr.str()
|
||||
|
||||
|
||||
def test_internal_errors_propagate_to_master(testdir):
|
||||
def test_internal_errors_propagate_to_controller(testdir):
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
def pytest_collection_modifyitems():
|
||||
@@ -1408,12 +1408,18 @@ class TestAPI:
|
||||
del fake_request.config.workerinput
|
||||
assert not xdist.is_xdist_worker(fake_request)
|
||||
|
||||
def test_is_xdist_master(self, fake_request):
|
||||
def test_is_xdist_controller(self, fake_request):
|
||||
|
||||
assert not xdist.is_xdist_master(fake_request)
|
||||
assert not xdist.is_xdist_controller(fake_request)
|
||||
|
||||
del fake_request.config.workerinput
|
||||
assert xdist.is_xdist_master(fake_request)
|
||||
assert xdist.is_xdist_controller(fake_request)
|
||||
|
||||
fake_request.config.option.dist = "no"
|
||||
assert not xdist.is_xdist_master(fake_request)
|
||||
assert not xdist.is_xdist_controller(fake_request)
|
||||
|
||||
def test_get_xdist_worker_id(self, fake_request):
|
||||
assert xdist.get_xdist_worker_id(fake_request) == "gw5"
|
||||
|
||||
Reference in New Issue
Block a user