Skip to content

Commit 1189ae4

Browse files
Merge pull request #624 from pytest-dev/fix-592-use-controller
prepare #592: replace master with controller where we can
2 parents 89c86af + 9e4e8b7 commit 1189ae4

File tree

8 files changed

+56
-21
lines changed

8 files changed

+56
-21
lines changed

README.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,18 @@ Since version 2.0, the following functions are also available in the ``xdist`` m
285285
"""
286286
287287
def is_xdist_master(request_or_session) -> bool:
288-
"""Return `True` if this is the xdist master, `False` otherwise
288+
"""Return `True` if this is the xdist controller, `False` otherwise
289+
290+
Note: this method also returns `False` when distribution has not been
291+
activated at all.
292+
293+
deprecated alias for is_xdist_controller
294+
295+
:param request_or_session: the `pytest` `request` or `session` object
296+
"""
297+
298+
def is_xdist_controller(request_or_session) -> bool:
299+
"""Return `True` if this is the xdist controller, `False` otherwise
289300
290301
Note: this method also returns `False` when distribution has not been
291302
activated at all.
@@ -295,7 +306,7 @@ Since version 2.0, the following functions are also available in the ``xdist`` m
295306
296307
def get_xdist_worker_id(request_or_session) -> str:
297308
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
298-
if running on the 'master' node.
309+
if running on the controller node.
299310
300311
If not distributing tests (for example passing `-n0` or not passing `-n` at all) also return 'master'.
301312

changelog/592.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace master with controller where ever possible.

src/xdist/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
from xdist.plugin import is_xdist_worker, is_xdist_master, get_xdist_worker_id
1+
from xdist.plugin import (
2+
is_xdist_worker,
3+
is_xdist_master,
4+
get_xdist_worker_id,
5+
is_xdist_controller,
6+
)
27
from xdist._version import version as __version__
38

4-
__all__ = ["__version__", "is_xdist_worker", "is_xdist_master", "get_xdist_worker_id"]
9+
__all__ = [
10+
"__version__",
11+
"is_xdist_worker",
12+
"is_xdist_master",
13+
"is_xdist_controller",
14+
"get_xdist_worker_id",
15+
]

src/xdist/dsession.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def pytest_sessionfinish(self, session):
8787
self._session = None
8888

8989
def pytest_collection(self):
90-
# prohibit collection of test items in master process
90+
# prohibit collection of test items in controller process
9191
return True
9292

9393
@pytest.mark.trylast
@@ -240,7 +240,7 @@ def worker_collectionfinish(self, node, ids):
240240
return
241241
self.config.hook.pytest_xdist_node_collection_finished(node=node, ids=ids)
242242
# tell session which items were effectively collected otherwise
243-
# the master node will finish the session with EXIT_NOTESTSCOLLECTED
243+
# the controller node will finish the session with EXIT_NOTESTSCOLLECTED
244244
self._session.testscollected = len(ids)
245245
self.sched.add_node_collection(node, ids)
246246
if self.terminal:

src/xdist/newhooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def pytest_testnodedown(node, error):
4848

4949

5050
def pytest_xdist_node_collection_finished(node, ids):
51-
"""called by the master node when a node finishes collecting.
51+
"""called by the controller node when a worker node finishes collecting.
5252
"""
5353

5454

src/xdist/plugin.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ def is_xdist_worker(request_or_session) -> bool:
227227
return hasattr(request_or_session.config, "workerinput")
228228

229229

230-
def is_xdist_master(request_or_session) -> bool:
231-
"""Return `True` if this is the xdist master, `False` otherwise
230+
def is_xdist_controller(request_or_session) -> bool:
231+
"""Return `True` if this is the xdist controller, `False` otherwise
232232
233233
Note: this method also returns `False` when distribution has not been
234234
activated at all.
@@ -241,9 +241,13 @@ def is_xdist_master(request_or_session) -> bool:
241241
)
242242

243243

244+
# ALIAS: TODO, deprecate (#592)
245+
is_xdist_master = is_xdist_controller
246+
247+
244248
def get_xdist_worker_id(request_or_session) -> str:
245249
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
246-
if running on the 'master' node.
250+
if running on the controller node.
247251
248252
If not distributing tests (for example passing `-n0` or not passing `-n` at all)
249253
also return 'master'.
@@ -253,6 +257,7 @@ def get_xdist_worker_id(request_or_session) -> str:
253257
if hasattr(request_or_session.config, "workerinput"):
254258
return request_or_session.config.workerinput["workerid"]
255259
else:
260+
# TODO: remove "master", ideally for a None
256261
return "master"
257262

258263

@@ -261,6 +266,7 @@ def worker_id(request):
261266
"""Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
262267
if running on the master node.
263268
"""
269+
# TODO: remove "master", ideally for a None
264270
return get_xdist_worker_id(request)
265271

266272

src/xdist/remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def pytest_runtest_logreport(self, report):
121121
self.sendevent("testreport", data=data)
122122

123123
def pytest_collectreport(self, report):
124-
# send only reports that have not passed to master as optimization (#330)
124+
# send only reports that have not passed to controller as optimization (#330)
125125
if not report.passed:
126126
data = self.config.hook.pytest_report_to_serializable(
127127
config=self.config, report=report
@@ -144,7 +144,7 @@ def serialize_warning_message(warning_message):
144144
message_class_name = type(warning_message.message).__name__
145145
message_str = str(warning_message.message)
146146
# check now if we can serialize the warning arguments (#349)
147-
# if not, we will just use the exception message on the master node
147+
# if not, we will just use the exception message on the controller node
148148
try:
149149
dumps(warning_message.message.args)
150150
except DumpError:

testing/acceptance_test.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def pytest_load_initial_conftests(early_config):
244244
def test_data_exchange(self, testdir):
245245
testdir.makeconftest(
246246
"""
247-
# This hook only called on master.
247+
# This hook only called on the controlling process.
248248
def pytest_configure_node(node):
249249
node.workerinput['a'] = 42
250250
node.workerinput['b'] = 7
@@ -257,7 +257,7 @@ def pytest_configure(config):
257257
r = a + b
258258
config.workeroutput['r'] = r
259259
260-
# This hook only called on master.
260+
# This hook only called on the controlling process.
261261
def pytest_testnodedown(node, error):
262262
node.config.calc_result = node.workeroutput['r']
263263
@@ -289,7 +289,7 @@ def pytest_sessionfinish(session):
289289
# on the worker
290290
if hasattr(session.config, 'workeroutput'):
291291
session.config.workeroutput['s2'] = 42
292-
# on the master
292+
# on the controller
293293
def pytest_testnodedown(node, error):
294294
assert node.workeroutput['s2'] == 42
295295
print ("s2call-finished")
@@ -503,7 +503,7 @@ def pytest_sessionfinish(session):
503503
if hasattr(session.config, 'workerinput'):
504504
name = "worker"
505505
else:
506-
name = "master"
506+
name = "controller"
507507
with open(name, "w") as f:
508508
f.write("xy")
509509
# let's fail on the worker
@@ -524,12 +524,12 @@ def test_hello():
524524
d = result.parseoutcomes()
525525
assert d["passed"] == 1
526526
assert testdir.tmpdir.join("worker").check()
527-
assert testdir.tmpdir.join("master").check()
527+
assert testdir.tmpdir.join("controller").check()
528528

529529

530530
def test_session_testscollected(testdir):
531531
"""
532-
Make sure master node is updating the session object with the number
532+
Make sure controller node is updating the session object with the number
533533
of tests collected from the workers.
534534
"""
535535
testdir.makepyfile(
@@ -574,7 +574,7 @@ def test_hello(myarg):
574574

575575

576576
def test_config_initialization(testdir, monkeypatch, pytestconfig):
577-
"""Ensure workers and master are initialized consistently. Integration test for #445"""
577+
"""Ensure workers and controller are initialized consistently. Integration test for #445"""
578578
testdir.makepyfile(
579579
**{
580580
"dir_a/test_foo.py": """
@@ -1138,7 +1138,7 @@ def test_aaa1(crasher):
11381138
assert "INTERNALERROR" not in result.stderr.str()
11391139

11401140

1141-
def test_internal_errors_propagate_to_master(testdir):
1141+
def test_internal_errors_propagate_to_controller(testdir):
11421142
testdir.makeconftest(
11431143
"""
11441144
def pytest_collection_modifyitems():
@@ -1408,12 +1408,18 @@ def test_is_xdist_worker(self, fake_request):
14081408
del fake_request.config.workerinput
14091409
assert not xdist.is_xdist_worker(fake_request)
14101410

1411-
def test_is_xdist_master(self, fake_request):
1411+
def test_is_xdist_controller(self, fake_request):
1412+
14121413
assert not xdist.is_xdist_master(fake_request)
1414+
assert not xdist.is_xdist_controller(fake_request)
1415+
14131416
del fake_request.config.workerinput
14141417
assert xdist.is_xdist_master(fake_request)
1418+
assert xdist.is_xdist_controller(fake_request)
1419+
14151420
fake_request.config.option.dist = "no"
14161421
assert not xdist.is_xdist_master(fake_request)
1422+
assert not xdist.is_xdist_controller(fake_request)
14171423

14181424
def test_get_xdist_worker_id(self, fake_request):
14191425
assert xdist.get_xdist_worker_id(fake_request) == "gw5"

0 commit comments

Comments
 (0)