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
211
211
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
212
212
213
213
To 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.
217
215
218
216
Example:
219
217
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
-
228
218
.. code-block :: python
229
219
230
220
# 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
-
238
221
def pytest_configure (config ):
239
222
worker_id = os.environ.get(" PYTEST_XDIST_WORKER" )
240
223
if worker_id is not None :
241
224
log_file = config.getini(" worker_log_file" )
242
225
logging.basicConfig(
243
226
format = config.getini(" log_file_format" ),
244
- filename = log_file.format( worker_id = worker_id) ,
227
+ filename = f " test_ { worker_id} .log " ,
245
228
level = config.getini(" log_file_level" ),
246
229
)
247
230
You can’t perform that action at this time.
0 commit comments