transformers - 💡(How to fix) Fix [Bug] pytest-xdist workers race on captured_info.txt in patched testing utils [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#45561Fetched 2026-04-23 07:23:03
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×1mentioned ×1subscribed ×1

Fix Action

Fix / Workaround

  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.
RAW_BUFFERClick to expand / collapse

System Info

Transformers=5.6.0.dev0 (local checkout 85099df959); 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

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 58dcab6ae281f04fbc3a2afb7b24235795ca885a). 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.

extent analysis

TL;DR

Use worker-specific filenames for captured debugging output to avoid cross-worker clobbering.

Guidance

  • Identify the shared output directory _PATCHED_TESTING_METHODS_OUTPUT_DIR and ensure each worker has its own isolated directory or filename.
  • Modify _prepare_debugging_info() to append the worker ID to the captured_info.txt filename, such as captured_info_gw0.txt and captured_info_gw1.txt.
  • Update patch_testing_methods_to_collect_info() to handle the new worker-specific filenames.
  • Verify the fix by running tests under pytest -n 2 and checking that each worker's output is correctly isolated.

Example

# Example of modifying _prepare_debugging_info() to use worker-specific filenames
worker_id = os.environ.get('PYTEST_XDIST_WORKER', 'gw0')
filename = f"captured_info_{worker_id}.txt"
with open(filename, 'a') as f:
    # Append debugging info to the worker-specific file
    f.write(debugging_info)

Notes

The provided candidate fix on the forked repository (https://github.com/oleksii-tumanov/transformers/tree/fix/testing-utils-xdist-captured-info) may be a good starting point for implementing the solution.

Recommendation

Apply a workaround by using worker-specific filenames, as this approach avoids cross-worker clobbering while preserving the current single-file behavior for non-xdist runs.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

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.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING