File tree Expand file tree Collapse file tree 1 file changed +2
-19
lines changed Expand file tree Collapse file tree 1 file changed +2
-19
lines changed Original file line number Diff line number Diff line change @@ -211,37 +211,20 @@ Creating one log file for each worker
211211^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
212212
213213To create one log file for each worker with ``pytest-xdist ``, you can leverage :envvar: `PYTEST_XDIST_WORKER `
214- an option to ``pytest.ini `` for the file base name. Then, in ``conftest.py ``,
215- register it with ``pytest_addoption(parser) `` and use ``pytest_configure(config) ``
216- to rename it with the worker id.
214+ to generate a unique filename for each worker.
217215
218216Example:
219217
220- .. code-block :: ini
221-
222- [pytest]
223- log_file_format = %(asctime)s %(name)s %(levelname)s %(message)s
224- log_file_level = INFO
225- worker_log_file = tests_{worker_id}.log
226-
227-
228218.. code-block :: python
229219
230220 # content of conftest.py
231- def pytest_addoption (parser ):
232- parser.addini(
233- " worker_log_file" ,
234- help = " Similar to log_file, but %w will be replaced with a worker identifier." ,
235- )
236-
237-
238221 def pytest_configure (config ):
239222 worker_id = os.environ.get(" PYTEST_XDIST_WORKER" )
240223 if worker_id is not None :
241224 log_file = config.getini(" worker_log_file" )
242225 logging.basicConfig(
243226 format = config.getini(" log_file_format" ),
244- filename = log_file.format( worker_id = worker_id) ,
227+ filename = f " test_ { worker_id} .log " ,
245228 level = config.getini(" log_file_level" ),
246229 )
247230
You can’t perform that action at this time.
0 commit comments