@@ -37,36 +37,11 @@ well, under the ``worker_id`` attribute.
37
37
38
38
Since version 2.0, the following functions are also available in the ``xdist `` module:
39
39
40
- .. code-block :: python
41
-
42
- def is_xdist_worker (request_or_session ) -> bool :
43
- """ Return `True` if this is an xdist worker, `False` otherwise
44
-
45
- :param request_or_session: the `pytest` `request` or `session` object
46
- """
47
-
48
- def is_xdist_controller (request_or_session ) -> bool :
49
- """ Return `True` if this is the xdist controller, `False` otherwise
50
-
51
- Note: this method also returns `False` when distribution has not been
52
- activated at all.
53
-
54
- :param request_or_session: the `pytest` `request` or `session` object
55
- """
56
-
57
- def is_xdist_master (request_or_session ) -> bool :
58
- """ Deprecated alias for is_xdist_controller."""
59
-
60
- def get_xdist_worker_id (request_or_session ) -> str :
61
- """ Return the id of the current worker ('gw0', 'gw1', etc) or 'master'
62
- if running on the controller node.
63
-
64
- If not distributing tests (for example passing `-n0` or not passing `-n` at all)
65
- also return 'master'.
66
-
67
- :param request_or_session: the `pytest` `request` or `session` object
68
- """
69
40
41
+ .. autofunction :: xdist.is_xdist_worker
42
+ .. autofunction :: xdist.is_xdist_controller
43
+ .. autofunction :: xdist.is_xdist_master
44
+ .. autofunction :: xdist.get_xdist_worker_id
70
45
71
46
Identifying workers from the system environment
72
47
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -102,6 +77,7 @@ wanted to create a separate database for each test run:
102
77
import pytest
103
78
from posix_ipc import Semaphore, O_CREAT
104
79
80
+
105
81
@pytest.fixture (scope = " session" , autouse = True )
106
82
def create_unique_database (testrun_uid ):
107
83
""" create a unique database for this particular test run """
@@ -111,6 +87,7 @@ wanted to create a separate database for each test run:
111
87
if not database_exists(database_url):
112
88
create_database(database_url)
113
89
90
+
114
91
@pytest.fixture ()
115
92
def db (testrun_uid ):
116
93
""" retrieve unique database """
@@ -252,17 +229,20 @@ Example:
252
229
253
230
# content of conftest.py
254
231
def pytest_addoption (parser ):
255
- parser.addini(' worker_log_file' , help = ' Similar to log_file, but %w will be replaced with a worker identifier.' )
232
+ parser.addini(
233
+ " worker_log_file" ,
234
+ help = " Similar to log_file, but %w will be replaced with a worker identifier." ,
235
+ )
256
236
257
237
258
238
def pytest_configure (config ):
259
- worker_id = os.environ.get(' PYTEST_XDIST_WORKER' )
239
+ worker_id = os.environ.get(" PYTEST_XDIST_WORKER" )
260
240
if worker_id is not None :
261
- log_file = config.getini(' worker_log_file' )
241
+ log_file = config.getini(" worker_log_file" )
262
242
logging.basicConfig(
263
- format = config.getini(' log_file_format' ),
243
+ format = config.getini(" log_file_format" ),
264
244
filename = log_file.format(worker_id = worker_id),
265
- level = config.getini(' log_file_level' )
245
+ level = config.getini(" log_file_level" ),
266
246
)
267
247
268
248
0 commit comments