diff --git a/AUTHORS.rst b/AUTHORS.rst index 9d7a9a7..8187028 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -11,3 +11,4 @@ These people have contributed to `pytest-services`, in alphabetical order: * `Jason R. Coombs `_ * `Joep van Dijken `_ * `Oleg Pidsadnyi `_ +* `Zac Hatfield-Dodds `_ diff --git a/CHANGES.rst b/CHANGES.rst index 353fab7..35cf7b0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,12 @@ Changelog ========= +2.1.0 +----- + +- #34: Deprecated ``slave_id`` fixture in favor of ``worker_id``, + for compatibility with ``pytest-xdist`` 2. + 2.0.1 ----- diff --git a/README.rst b/README.rst index a6ba914..4454300 100644 --- a/README.rst +++ b/README.rst @@ -48,9 +48,10 @@ Fixtures Infrastructure fixtures *********************** -* slave_id - Id of the slave if tests are run using pytest-xdist_. It is set to `local` if tests are not run using +* worker_id + Id of the worker if tests are run using pytest-xdist_. It is set to `local` if tests are not run using pytest-xdist_ (with `--dist` command line option set to `load`). + Has a deprecated alias ``slave_id`` which will be removed in a future version. * session_id Test session id. Globally unique, and of course also guaranteed to be different for potentially multiple test sessions running on same test node via pytest-xdist_. diff --git a/pytest_services/log.py b/pytest_services/log.py index 745683e..9e2daca 100644 --- a/pytest_services/log.py +++ b/pytest_services/log.py @@ -8,8 +8,8 @@ @pytest.fixture(scope='session') -def services_log(slave_id): - """A services_logger with the slave id.""" +def services_log(worker_id): + """A services_logger with the worker id.""" handler = None for kwargs in (dict(socktype=socket.SOCK_RAW), dict(socktype=socket.SOCK_STREAM), dict()): try: @@ -18,7 +18,7 @@ def services_log(slave_id): break except (IOError, TypeError): pass - logger = logging.getLogger('[{slave_id}] {name}'.format(name=__name__, slave_id=slave_id)) + logger = logging.getLogger('[{worker_id}] {name}'.format(name=__name__, worker_id=worker_id)) logger.setLevel(logging.DEBUG) if handler and workaround_issue_20(handler): logger.propagate = 0 diff --git a/pytest_services/service.py b/pytest_services/service.py index 77c1e40..2f57302 100644 --- a/pytest_services/service.py +++ b/pytest_services/service.py @@ -15,15 +15,15 @@ @pytest.fixture(scope='session') -def run_services(request, slave_id): +def run_services(request, worker_id): """Indicate whether the services should run or not.""" - return slave_id != 'local' or request.config.option.run_services + return worker_id != 'local' or request.config.option.run_services @pytest.fixture(scope='session') -def slave_id(request): +def worker_id(request): """ - The id of the slave if tests are run using xdist. + The id of the worker if tests are run using xdist. It is set to `'local'` if tests are not run using xdist. @@ -31,20 +31,27 @@ def slave_id(request): that belong to different test sessions. """ - return WRONG_FILE_NAME_CHARS_RE.sub('_', getattr(request.config, 'slaveinput', {}).get('slaveid', 'local')) + return WRONG_FILE_NAME_CHARS_RE.sub('_', getattr(request.config, 'workerinput', {}).get('workerid', 'local')) @pytest.fixture(scope='session') -def session_id(request, slave_id, run_services): +def slave_id(request, worker_id): + msg = "The `slave_id` fixture is deprecated; use `worker_id` instead." + warnings.warn(msg, DeprecationWarning) + return worker_id + + +@pytest.fixture(scope='session') +def session_id(request, worker_id, run_services): """The test session id. It is supposed to be globally unique. """ # UUID should be enough, other fields are added for the debugging purposes. - session_id = '{random}-{slave_id}'.format( + session_id = '{random}-{worker_id}'.format( random=uuid.uuid4().hex, - slave_id=slave_id, + worker_id=worker_id, ) return session_id