Skip to content

[Bug] pytest-xdist workers race on captured_info.txt in patched testing utils #45561

@oleksii-tumanov

Description

@oleksii-tumanov

System Info

Transformers=5.6.0.dev0 (local checkout 85099df);
Python=3.13.5;
Platform=macOS-26.2-arm64-arm-64bit-Mach-O;
pytest=8.4.2;
pytest-xdist=3.8.0

Who can help?

@ydshieh @SunMarc

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

This issue affects internal test utilities and does not involve example scripts or a user dataset/task.

  1. In src/transformers/testing_utils.py, _prepare_debugging_info() appends to captured_info.txt and patch_testing_methods_to_collect_info() unlinks that same file.
  2. Run tests under pytest -n 2 with workers sharing the same _PATCHED_TESTING_METHODS_OUTPUT_DIR.
  3. Observe that workers write to and reset the same captured_info.txt, so one worker can delete or interleave another worker's captured debugging output.

I checked for overlapping issues and PRs and did not find a direct match.
I have a candidate fix with focused tests on my fork here: https://github.com/oleksii-tumanov/transformers/tree/fix/testing-utils-xdist-captured-info (commit 58dcab6). I am opening the issue first for coordination before submitting an upstream PR.

Expected behavior

Each xdist worker should isolate its captured debugging output instead of sharing one captured_info.txt file. For example, worker-specific filenames such as captured_info_gw0.txt and captured_info_gw1.txt would avoid cross-worker clobbering while preserving the current single-file behavior for non-xdist runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions