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

Abierto Apto para principiantes
#627 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
74/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
testing

Línea de trabajo

Empieza siguiendo cómo se expande cache_invalidation_files en watched_file_hashes y cómo _changed_hashed_files(restrict_to=...) filtra esas rutas; compara los dos comportamientos de coincidencia descritos en el issue. Reproduce el comportamiento con archivos de nivel superior y anidados bajo tests y luego comprueba que ambos provocan una nueva ejecución con el patrón recursivo. El issue no indica un archivo de prueba, así que localiza o añade una prueba de regresión específica para ambas rutas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
1.5k
Forks
190
Merge medio
1 d 11 h
PR fusionados (30 d)
8

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de boxed/mutmut

Todos los issues de boxed/mutmut

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.