Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

tests/test_generate_images.py::test_generate_og_images collides with itself under concurrent pytest runs (fixed-name temp dir under the real repo root, not inside pytest's tmp_path)

Chiusa Adatta ai principianti
#707 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
testing

Direzione di ricerca

Il problema si trova in tests/test_generate_images.py nella funzione test_generate_og_images. Osserva come test_root viene costruito utilizzando script.ROOT e tmp_path.name. La correzione consiste nell'usare l'unico tmp_path fornito da pytest. Leggi il test per comprendere il monkeypatching delle directory di output. Esegui il test localmente e riproduci il problema di concorrenza per verificare la correzione. Assicurati che il test passi e che non rimangano directory residue dopo la pulizia.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Where: tests/test_generate_images.py, test_generate_og_images - specifically test_root = script.ROOT / f".tmp-test-{tmp_path.name}" followed by test_root.mkdir().

The gap: The test builds its scratch directory as script.ROOT / f".tmp-test-{tmp_path.name}" - i.e. under the real repository root (script.ROOT, a fixed path shared by every process), using only tmp_path.name (e.g. "test_generate_og_images0", which is deterministic per pytest session/worker, not globally unique) rather than the full, process-unique tmp_path. Two concurrent pytest invocations therefore compute the identical test_root path and race on mkdir().

Repro (single run passes cleanly):

$ python3 -m pytest tests/test_generate_images.py::test_generate_og_images -q
1 passed in 5.92s

Repro (two concurrent runs collide):

$ (python3 -m pytest tests/test_generate_images.py::test_generate_og_images -q > /tmp/run1.log 2>&1 &)
$ (python3 -m pytest tests/test_generate_images.py::test_generate_og_images -q > /tmp/run2.log 2>&1 &)
$ sleep 8; cat /tmp/run2.log
FAILED tests/test_generate_images.py::test_generate_og_images - FileExistsError: [Errno 17] File exists: '/Users/.../Fair-Code/.tmp-test-test_generate_og_images0'

The failing process hits FileExistsError on the mkdir() call itself, which sits before the try/finally cleanup block, so its own shutil.rmtree cleanup never even applies to it - the surviving directory is only ever cleaned up by whichever process created it, making the outcome timing-dependent. Confirmed no stray directory or git changes were left behind after a normal run (git status --short clean), but a differently-timed collision could leave one.

Fix direction: Use tmp_path itself (already unique per test invocation) or tmp_path_factory's base temp dir instead of constructing a new path under script.ROOT; if the script under test requires monkeypatching absolute output directories anyway (which this test already does), there's no need for test_root to live under the repo root at all.

Lingua principale
HTML
Stelle
47
Fork
45
Merge medio
1h 53m
PR unite (30g)
97

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di yakew7/Fair-Code

Tutte le issue di yakew7/Fair-Code

Issue simili

Altre issue su Testing & QA

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.