Skip to content

Commit 319a8b8

Browse files
authored
Merge pull request #38 from dmtucker/xdist2
2 parents 8af069d + 49d9439 commit 319a8b8

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

content/shared_directory_xdist/contents.lr

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,26 @@ def pytest_unconfigure(config):
3636
shutil.rmtree(config.shared_directory)
3737

3838

39+
def workerinput(node):
40+
"""Get node.workerinput (xdist 2+), node.slaveinput (xdist <2), or None."""
41+
for attr in ['workerinput', 'slaveinput']:
42+
try:
43+
return getattr(node, attr)
44+
except AttributeError:
45+
continue
46+
return None
47+
48+
3949
def pytest_configure_node(node):
4050
"""xdist hook"""
41-
node.slaveinput['shared_dir'] = node.config.shared_directory
51+
workerinput(node)['shared_dir'] = node.config.shared_directory
4252

4353

4454
def is_master(config):
4555
"""True if the code running the given pytest.config object is running in a xdist master
4656
node or not running xdist at all.
4757
"""
48-
return not hasattr(config, 'slaveinput')
58+
return not workerinput(config)
4959

5060

5161
@pytest.fixture
@@ -56,11 +66,11 @@ def shared_directory(request):
5666
if is_master(request.config):
5767
return request.config.shared_directory
5868
else:
59-
return request.config.slaveinput['shared_dir']
69+
return workerinput(request.config)['shared_dir']
6070

6171
```
6272

63-
Anything put in `node.slaveinput` dictionary during the `pytest_configure_node`
73+
Anything put in `node.workerinput` dictionary during the `pytest_configure_node`
6474
xdist hook can be accessed by the worker nodes later. You can put any
6575
simple builtin type, like lists, strings, tuples, etc.
6676

@@ -83,4 +93,4 @@ hook
8393
fixture
8494
xdist
8595
---
86-
tldr: Use `request.config.slaveinput` to send information from master to worker nodes in pytest-xdist
96+
tldr: Use `request.config.workerinput` to send information from master to worker nodes in pytest-xdist

0 commit comments

Comments
 (0)