Skip to content

FIX: use tmp_path for hardcoded test files to fix xdist races#1797

Merged
romanlutz merged 1 commit into
microsoft:mainfrom
romanlutz:romanlutz/fix-xdist-races-tmp-path
May 26, 2026
Merged

FIX: use tmp_path for hardcoded test files to fix xdist races#1797
romanlutz merged 1 commit into
microsoft:mainfrom
romanlutz:romanlutz/fix-xdist-races-tmp-path

Conversation

@romanlutz
Copy link
Copy Markdown
Contributor

Fixes the same xdist race as #1795, in three more places.

Three unit tests write to CWD-relative hardcoded paths (test.png, sample_file.png) and clean them up manually:

  • tests/unit/prompt_converter/test_add_text_image_converter.py
  • tests/unit/models/test_seed.py
  • tests/unit/prompt_converter/test_qr_code_converter.py

Under pytest -n auto (default --dist=load) workers share CWD and race on these names. Worse, the first two use the same filename test.png, so they race across files even under CI's --dist=loadfile.

Fix

Inject tmp_path into each test and write under it. Per-test temp dirs are unique per worker; pytest cleans them up, so manual os.remove calls go away too. Same surgical pattern as #1795.

Verification

  • pytest <files> sequentially: 124 passed in ~25s
  • pytest <files> -n auto x5 runs: 124 passed every run

Notes

Investigation and patch were drafted with Copilot CLI assistance during review of #1795; I verified the bug pattern and validated the fix.

Three tests wrote to CWD-relative hardcoded paths (`test.png`,

`sample_file.png`) and cleaned them up manually. Under

`pytest -n auto` (default `--dist=load`) workers share CWD and race

on these names. Worse, two of the files used the same `test.png` so

they raced across files even under CI's `--dist=loadfile`.

Inject `tmp_path` into each test and write under it. The per-test

temp dir is unique per worker, removing the race, and pytest cleans it

up automatically so manual `os.remove` calls go away.

Same pattern as microsoft#1795 (test_video_scorer.py).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz romanlutz added this pull request to the merge queue May 26, 2026
Merged via the queue into microsoft:main with commit e95564a May 26, 2026
48 checks passed
@romanlutz romanlutz deleted the romanlutz/fix-xdist-races-tmp-path branch May 26, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants