Skip to content

Commit edf4728

Browse files
committed
"slave" -> "worker" for xdist compat
Closes #34.
1 parent 9a085e7 commit edf4728

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ These people have contributed to `pytest-services`, in alphabetical order:
1111
* `Jason R. Coombs <[email protected]>`_
1212
* `Joep van Dijken <[email protected]>`_
1313
* `Oleg Pidsadnyi <[email protected]>`_
14+
* `Zac Hatfield-Dodds <[email protected]>`_

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
2.1.0
5+
-----
6+
7+
- #34: Deprecated ``slave_id`` fixture in favor of ``worker_id``,
8+
for compatibility with ``pytest-xdist`` 2.
9+
410
2.0.1
511
-----
612

README.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ Fixtures
4848
Infrastructure fixtures
4949
***********************
5050

51-
* slave_id
52-
Id of the slave if tests are run using pytest-xdist_. It is set to `local` if tests are not run using
51+
* worker_id
52+
Id of the worker if tests are run using pytest-xdist_. It is set to `local` if tests are not run using
5353
pytest-xdist_ (with `--dist` command line option set to `load`).
54+
Has a deprecated alias ``slave_id`` which will be removed in a future version.
5455
* session_id
5556
Test session id. Globally unique, and of course also guaranteed to be different for potentially multiple test
5657
sessions running on same test node via pytest-xdist_.

pytest_services/log.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
@pytest.fixture(scope='session')
11-
def services_log(slave_id):
12-
"""A services_logger with the slave id."""
11+
def services_log(worker_id):
12+
"""A services_logger with the worker id."""
1313
handler = None
1414
for kwargs in (dict(socktype=socket.SOCK_RAW), dict(socktype=socket.SOCK_STREAM), dict()):
1515
try:
@@ -18,7 +18,7 @@ def services_log(slave_id):
1818
break
1919
except (IOError, TypeError):
2020
pass
21-
logger = logging.getLogger('[{slave_id}] {name}'.format(name=__name__, slave_id=slave_id))
21+
logger = logging.getLogger('[{worker_id}] {name}'.format(name=__name__, worker_id=worker_id))
2222
logger.setLevel(logging.DEBUG)
2323
if handler and workaround_issue_20(handler):
2424
logger.propagate = 0

pytest_services/service.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,43 @@
1515

1616

1717
@pytest.fixture(scope='session')
18-
def run_services(request, slave_id):
18+
def run_services(request, worker_id):
1919
"""Indicate whether the services should run or not."""
20-
return slave_id != 'local' or request.config.option.run_services
20+
return worker_id != 'local' or request.config.option.run_services
2121

2222

2323
@pytest.fixture(scope='session')
24-
def slave_id(request):
24+
def worker_id(request):
2525
"""
26-
The id of the slave if tests are run using xdist.
26+
The id of the worker if tests are run using xdist.
2727
2828
It is set to `'local'` if tests are not run using xdist.
2929
3030
The id is unique for a test run. An id may clash if there are two workers
3131
that belong to different test sessions.
3232
3333
"""
34-
return WRONG_FILE_NAME_CHARS_RE.sub('_', getattr(request.config, 'slaveinput', {}).get('slaveid', 'local'))
34+
return WRONG_FILE_NAME_CHARS_RE.sub('_', getattr(request.config, 'workerinput', {}).get('workerid', 'local'))
3535

3636

3737
@pytest.fixture(scope='session')
38-
def session_id(request, slave_id, run_services):
38+
def slave_id(request, worker_id):
39+
msg = "The `slave_id` fixture is deprecated; use `worker_id` instead."
40+
warnings.warn(msg, DeprecationWarning)
41+
return worker_id
42+
43+
44+
@pytest.fixture(scope='session')
45+
def session_id(request, worker_id, run_services):
3946
"""The test session id.
4047
4148
It is supposed to be globally unique.
4249
4350
"""
4451
# UUID should be enough, other fields are added for the debugging purposes.
45-
session_id = '{random}-{slave_id}'.format(
52+
session_id = '{random}-{worker_id}'.format(
4653
random=uuid.uuid4().hex,
47-
slave_id=slave_id,
54+
worker_id=worker_id,
4855
)
4956

5057
return session_id

0 commit comments

Comments
 (0)