@@ -37,36 +37,11 @@ well, under the ``worker_id`` attribute.
3737
3838Since version 2.0, the following functions are also available in the ``xdist `` module:
3939
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- """
6940
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
7045
7146Identifying workers from the system environment
7247^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -102,6 +77,7 @@ wanted to create a separate database for each test run:
10277 import pytest
10378 from posix_ipc import Semaphore, O_CREAT
10479
80+
10581 @pytest.fixture (scope = " session" , autouse = True )
10682 def create_unique_database (testrun_uid ):
10783 """ create a unique database for this particular test run """
@@ -111,6 +87,7 @@ wanted to create a separate database for each test run:
11187 if not database_exists(database_url):
11288 create_database(database_url)
11389
90+
11491 @pytest.fixture ()
11592 def db (testrun_uid ):
11693 """ retrieve unique database """
@@ -252,17 +229,20 @@ Example:
252229
253230 # content of conftest.py
254231 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+ )
256236
257237
258238 def pytest_configure (config ):
259- worker_id = os.environ.get(' PYTEST_XDIST_WORKER' )
239+ worker_id = os.environ.get(" PYTEST_XDIST_WORKER" )
260240 if worker_id is not None :
261- log_file = config.getini(' worker_log_file' )
241+ log_file = config.getini(" worker_log_file" )
262242 logging.basicConfig(
263- format = config.getini(' log_file_format' ),
243+ format = config.getini(" log_file_format" ),
264244 filename = log_file.format(worker_id = worker_id),
265- level = config.getini(' log_file_level' )
245+ level = config.getini(" log_file_level" ),
266246 )
267247
268248
0 commit comments