Skip to content

Commit 24f331c

Browse files
authored
Merge pull request #764 from nicoddemus/fix-log-worker
2 parents 2868896 + 34f6360 commit 24f331c

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

docs/how-to.rst

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -211,37 +211,20 @@ Creating one log file for each worker
211211
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
212212

213213
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.
217215

218216
Example:
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

0 commit comments

Comments
 (0)