diff --git a/README.rst b/README.rst index ed93b7cd..ae3097b2 100644 --- a/README.rst +++ b/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'. diff --git a/changelog/592.trivial.rst b/changelog/592.trivial.rst new file mode 100644 index 00000000..a240729e --- /dev/null +++ b/changelog/592.trivial.rst @@ -0,0 +1 @@ +Replace master with controller where ever possible. diff --git a/src/xdist/__init__.py b/src/xdist/__init__.py index 83ef7762..031a3d34 100644 --- a/src/xdist/__init__.py +++ b/src/xdist/__init__.py @@ -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", +] diff --git a/src/xdist/dsession.py b/src/xdist/dsession.py index 3db8e025..ab927fa2 100644 --- a/src/xdist/dsession.py +++ b/src/xdist/dsession.py @@ -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 @@ -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: diff --git a/src/xdist/newhooks.py b/src/xdist/newhooks.py index 4ac71960..0e2efe9b 100644 --- a/src/xdist/newhooks.py +++ b/src/xdist/newhooks.py @@ -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. """ diff --git a/src/xdist/plugin.py b/src/xdist/plugin.py index 2d8424d9..1eba32b8 100644 --- a/src/xdist/plugin.py +++ b/src/xdist/plugin.py @@ -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 (#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'. @@ -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) diff --git a/src/xdist/remote.py b/src/xdist/remote.py index 9aaf91b9..7f95b5cc 100644 --- a/src/xdist/remote.py +++ b/src/xdist/remote.py @@ -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 @@ -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: diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index c273bfac..382c9381 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -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 @@ -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'] @@ -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") @@ -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 @@ -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( @@ -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": """ @@ -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(): @@ -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"