pytest-dev / pytest-dev/pytest

Logfile clobbered when using xdist plugin

Open
#3,813 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: logging plugin: xdist type: enhancement
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

When using the pytest-xdist plugin, the pytest log file gets clobbered by one of the worker processes, so the resulting file contains only the logs from one worker.

This is because the log file always truncates and only supports a single filename:
https://github.com/pytest-dev/pytest/blob/3c23b5b0106b240597f57b1ce0bbfaebfcb8591c/src/_pytest/logging.py#L406-L409

It would be great if one of these options was implemented:

  1. Add the ability to specify the PID as part of the log filename (e.g. --log-file "something-%p.log")
  2. Add some internal way of changing it, so that the xdist plugin can make use of it, without having to completely do logging from scratch.

Versions:
pytest==3.6.4
pytest-forked==0.2
pytest-xdist==1.22.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read src/_pytest/logging.py around lines 406-409 and inspect how pytest-xdist starts worker processes. Compare the two proposed approaches; done means concurrent workers no longer truncate each other’s logs and the resulting files retain the expected worker output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.