Python: a test inside a package misses imports that resolve from its basedir

Abierto Apto para principiantes
#243 1 comentario 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
84/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, typescript
Área
devtools, testing

Línea de trabajo

Empieza en src/repo/adapters/python.ts, en resolvePythonGraph y la lógica de fileRoots por archivo. Lee las pruebas existentes del grafo de Python y añade un caso que coincida con la estructura del paquete services/api/tests del issue, donde test_app.py importa app del mismo directorio. Se considera terminado cuando cambiar services/api/app.py selecciona esa prueba y el análisis de extremo a extremo la informa como afectada.

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

Descripción

resolvePythonGraph (src/repo/adapters/python.ts, the fileRoots line in the per-file loop) adds a file's own directory to the import roots only when that directory has no __init__.py. pytest's default prepend import mode puts the file's basedir on sys.path: the first directory above the file's package. A test inside a package below the repository root can import modules beside that package, and DiffCI misses the edge.

pyproject.toml                    [tool.pytest.ini_options]
services/api/app.py               def f(): return 1
services/api/tests/__init__.py
services/api/tests/test_app.py    import app

python -m pytest services/api/tests/test_app.py passes (pytest 9.2).

Expected: a change to services/api/app.py selects services/api/tests/test_app.py.

Actual: no edge and no blocker (app is not first-party when seen from the root), so the change is selective with no tests:

resolvePythonGraph(
  ["services/api/app.py", "services/api/tests/__init__.py", "services/api/tests/test_app.py"],
  { "services/api/app.py": { imports: [] }, "services/api/tests/__init__.py": { imports: [] },
    "services/api/tests/test_app.py": { imports: [["app", 0, []]] } },
  { pythonFiles: ["test_*.py"], testpaths: [], pythonpath: [] },
  new Set(["services/api/tests/test_app.py"]),
); // { edges: [], blockers: [] }

End to end, ImpactAnalyzer returns fallbackRequired: false and no affected tests.

Fix: resolve against the basedir: the file's directory when it is not a package, otherwise the nearest ancestor without __init__.py.

Lenguaje dominante
TypeScript
Estrellas
0
Forks
4
Merge medio
18 h 41 min
PR fusionados (30 d)
48

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

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 DiffCI/core

Todos los issues de DiffCI/core

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.