@@ -36,16 +36,26 @@ def pytest_unconfigure(config):
36
36
shutil.rmtree(config.shared_directory)
37
37
38
38
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
+
39
49
def pytest_configure_node (node ):
40
50
""" xdist hook"""
41
- node.slaveinput [' shared_dir' ] = node.config.shared_directory
51
+ workerinput( node) [' shared_dir' ] = node.config.shared_directory
42
52
43
53
44
54
def is_master (config ):
45
55
""" True if the code running the given pytest.config object is running in a xdist master
46
56
node or not running xdist at all.
47
57
"""
48
- return not hasattr (config, ' slaveinput ' )
58
+ return not workerinput (config)
49
59
50
60
51
61
@pytest.fixture
@@ -56,11 +66,11 @@ def shared_directory(request):
56
66
if is_master(request.config):
57
67
return request.config.shared_directory
58
68
else :
59
- return request.config.slaveinput [' shared_dir' ]
69
+ return workerinput( request.config) [' shared_dir' ]
60
70
61
71
```
62
72
63
- Anything put in ` node.slaveinput ` dictionary during the ` pytest_configure_node `
73
+ Anything put in ` node.workerinput ` dictionary during the ` pytest_configure_node `
64
74
xdist hook can be accessed by the worker nodes later. You can put any
65
75
simple builtin type, like lists, strings, tuples, etc.
66
76
83
93
fixture
84
94
xdist
85
95
---
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