feat(coverage): import coverage.py data files (.coverage) (#6450)

Import a Coverage Report now reads coverage.py's .coverage data file; choosing one .coverage.* file of a parallel run imports all of them. The data only records executed lines and arcs, so coverage.py in the project's interpreter combines it into a scratch file (combine --keep, the user's files untouched) and writes Cobertura XML (xml -i) for the existing importer, run in the project directory so [paths] and excluded lines apply. Running the interpreter needs a trusted project; without trust, an interpreter or coverage.py the error says so and points to coverage xml output. Files without source in the project are listed without lines and the notification says to map them with [paths].

Closes #6392

Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-11-27 18:50:40 +08:00
1 джерело a0afc478c1
коміт 660becbaa4
11 files changed
+244 -16

No files matched your search

+7
Переглянути файл
@@ -114,6 +114,13 @@ it("says how many imported files are not in the project", async () => {
expect(backend.notify).toHaveBeenLastCalledWith(
expect.objectContaining({ level: "warning", body: "2 files of the report are not in this project." }),
);
backend.coverageImport.mockResolvedValue(ok({ ...data, runner: "coverage.py", files: [file, foreign("/ci/a.py")] }));
await importReport(report);
expect(backend.notify).toHaveBeenLastCalledWith(
expect.objectContaining({
body: "1 file of the data has no source in this project. Map it with [paths] in the coverage.py configuration.",
}),
);
backend.coverageImport.mockResolvedValue(ok(data));
await importReport(report);
expect(backend.notify).toHaveBeenLastCalledWith(expect.objectContaining({ level: "info", body: undefined }));
+14 -8
Переглянути файл
@@ -1,6 +1,6 @@
/**
* Coverage reports collected elsewhere: "Import a report collected in CI from
* disk" (lcov, JaCoCo or Cobertura XML, Go cover profile, SimpleCov) and "Manage Coverage Reports"
* disk" (lcov, JaCoCo or Cobertura XML, Go cover profile, SimpleCov, coverage.py data) and "Manage Coverage Reports"
* (choose the shown suite, delete suites and remembered imports).
*/
import { useMemo, useState } from "react";
@@ -43,6 +43,18 @@ async function pickReport(): Promise<string | null> {
});
}
/** Says how many files of an import are not in the project; coverage.py data maps them with `[paths]`. */
function outsideText(outside: number, runner: string): string | undefined {
if (!outside) return undefined;
if (runner === "coverage.py")
return outside === 1
? "1 file of the data has no source in this project. Map it with [paths] in the coverage.py configuration."
: tx`${outside} files of the data have no source in this project. Map them with [paths] in the coverage.py configuration.`;
return outside === 1
? "1 file of the report is not in this project."
: tx`${outside} files of the report are not in this project.`;
}
/** Imports `path` (asks for a file without one) and shows it like a run's suite. */
export async function importReport(path?: string): Promise<Suite | null> {
if (!isTauri()) {
@@ -73,13 +85,7 @@ export async function importReport(path?: string): Promise<Suite | null> {
level: outside ? "warning" : "info",
key: "coverage-import",
title: `Imported coverage '${suite.name}': ${formatPercent(covered!, total!)} lines`,
body: !data.files.length
? "The report covers no files of this project."
: outside === 1
? "1 file of the report is not in this project."
: outside
? tx`${outside} files of the report are not in this project.`
: undefined,
body: !data.files.length ? "The report covers no files of this project." : outsideText(outside, data.runner),
});
return suite;
} catch (e) {