cache_invalidation_files with `**` doesn't catch files at the top of the directory

Aperta Adatta ai principianti
#627 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
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
testing

Direzione di ricerca

Inizia seguendo come cache_invalidation_files viene espanso in watched_file_hashes e come _changed_hashed_files(restrict_to=...) filtra quei percorsi; confronta i due comportamenti di corrispondenza descritti nell’issue. Riproduci il problema con file al livello superiore e annidati sotto tests, poi verifica che entrambi attivino una nuova esecuzione per il pattern ricorsivo. L’issue non indica un file di test, quindi individua o aggiungi un test di regressione mirato per entrambi i percorsi.

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

Descrizione

mutmut 3.8.0 (the same matching code is still on master)

I tried this as a workaround for #626:

cache_invalidation_files = ["tests/**/*.py"]
on_dependency_change = "rerun"

It works for tests/sub/test_deep.py:

    1 non-Python file(s) changed; rerunning all mutants: tests/sub/test_deep.py
    calc.ops.x_is_adult__mutmut_1: survived
    calc.ops.x_is_adult__mutmut_2: survived

but not for tests/test_ops.py. With the script from #626 (bash repro.sh watch) the warm run
still says killed and doesn't print the "rerunning" line.

The baseline is built with Path(".").glob("tests/**/*.py"), where ** can match zero
directories, so tests/test_ops.py does end up in watched_file_hashes. But
_changed_hashed_files(restrict_to=cfg.cache_invalidation_files) then filters with
fnmatch, and for fnmatch **/ needs a literal slash:

>>> from fnmatch import fnmatch
>>> fnmatch("tests/test_ops.py", "tests/**/*.py")
False
>>> fnmatch("tests/a/b.py", "tests/**/*.py")
True

So the file is dropped, and _changed_hashed_files() returns an empty set even though the hash
changed. A top-level tests/conftest.py would never trigger a rerun either.

"tests/*.py" on its own has the opposite problem: the top-level file is caught, but the glob
doesn't recurse, so files in sub-directories never get into the baseline. Listing both works:

tests/**/*.py               top-level: missed   tests/sub/: caught
tests/*.py                  top-level: caught   tests/sub/: missed
tests/*.py + tests/**/*.py  top-level: caught   tests/sub/: caught

(checked each combination against a weakened test at both locations)

A fix could be to use the same matching in both places, e.g. PurePath.full_match() on 3.13+,
or check membership in the paths the glob returned.

Lingua principale
Python
Stelle
1.5k
Fork
190
Merge medio
1g 11h
PR unite (30g)
8

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 boxed/mutmut

Tutte le issue di boxed/mutmut

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.