Skip to content

Function-level selection

With a --coverage recording, Python and JS/TS tests are selected at function level: an edit to a function a test never executed selects nothing.

The recording keeps which function bodies ran (coverage.py line data mapped to each function’s body). Files are split into units: functions and methods, class headers, and module-level statements, each with its own comment-insensitive hash. A changed file selects a test only if:

  • a function it executed changed or was removed,
  • a changed module-level name (LIMIT = 5) or class header is mentioned by code that test ran, here or in an importer (from m import * always counts),
  • a class header changed and the test ran one of its methods, or
  • import-time code with no bound name changed (imports, bare calls, if and try blocks).

An unrelated function edit, an unexecuted function, or an edit to an if __name__ == "__main__": block selects nothing. Name matching is by identifier, not by call graph, so it errs toward selecting. Dynamic access by string (getattr(mod, "LIMIT")) is not seen.

V8 coverage has no usable line numbers (offsets refer to transformed code), but it lists every function by name with a call count. Files are split into units the same way (functions, const f = () => .., class methods, class headers, other statements) and a unit counts as executed when a function with its name was called.

This is conservative by construction:

  • same-named functions (run in two classes) share a verdict,
  • a unit the runtime never listed counts as executed,
  • if none of a file’s functions are recognised (names mangled by a transform) the file stays file-level,
  • export default, destructuring declarations, imports and re-exports, and any statement with no bound name are treated as “any change counts”; export * from makes every changed name relevant.

TypeScript types are tracked by name like any other declaration. Verified on Vitest 2 and Jest 29. Vitest is measured with --pool=threads because forked workers are killed before they flush V8 coverage.

Rust and Java/Kotlin recordings are file-level: a changed file selects every test that executed it.