Skip to content

Commit

Permalink
Merge pull request #624 from pytest-dev/fix-592-use-controller
Browse files Browse the repository at this point in the history
prepare #592: replace master with controller where we can
  • Loading branch information
RonnyPfannschmidt authored Feb 11, 2021
2 parents 89c86af + 9e4e8b7 commit 1189ae4
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 21 deletions.
15 changes: 13 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand 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'.
Expand Down
1 change: 1 addition & 0 deletions changelog/592.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace master with controller where ever possible.
15 changes: 13 additions & 2 deletions src/xdist/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
4 changes: 2 additions & 2 deletions src/xdist/dsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def pytest_sessionfinish(self, session):
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
Expand Down Expand Up @@ -240,7 +240,7 @@ def worker_collectionfinish(self, node, ids):
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:
Expand Down
2 changes: 1 addition & 1 deletion src/xdist/newhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""


Expand Down
12 changes: 9 additions & 3 deletions src/xdist/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -241,9 +241,13 @@ def is_xdist_master(request_or_session) -> bool:
)


# ALIAS: TODO, deprecate (#592)
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'.
Expand All @@ -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"


Expand All @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions src/xdist/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def pytest_runtest_logreport(self, report):
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
Expand All @@ -144,7 +144,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:
Expand Down
24 changes: 15 additions & 9 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def pytest_load_initial_conftests(early_config):
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
Expand All @@ -257,7 +257,7 @@ def pytest_configure(config):
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']
Expand Down Expand Up @@ -289,7 +289,7 @@ def pytest_sessionfinish(session):
# 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")
Expand Down Expand Up @@ -503,7 +503,7 @@ def pytest_sessionfinish(session):
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
Expand All @@ -524,12 +524,12 @@ def test_hello():
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(
Expand Down Expand Up @@ -574,7 +574,7 @@ def test_hello(myarg):


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": """
Expand Down Expand Up @@ -1138,7 +1138,7 @@ def test_aaa1(crasher):
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():
Expand Down Expand Up @@ -1408,12 +1408,18 @@ def test_is_xdist_worker(self, fake_request):
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"
Expand Down

0 comments on commit 1189ae4

Please sign in to comment.