Skip to content

Commit 63eb06a

Browse files
committed
fix: include Python runtime metadata for pytest suites
1 parent 1670db2 commit 63eb06a

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

src/mapper.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13412,9 +13412,55 @@ add_executable(headerapp include/headers.hpp)
1341213412

1341313413
expect(project.detected.commands.test).toBe("pytest");
1341413414
expect(suite?.ownedFiles).toEqual([{ path: "test_app.py", reason: "pytest file" }]);
13415+
expect(suite?.contextFiles).toEqual([
13416+
{ path: "pyproject.toml", reason: "python target runtime metadata" },
13417+
{ path: "test_app.py", reason: "nearby test" },
13418+
]);
13419+
expect(suite?.contextFiles).not.toContainEqual({
13420+
path: ".python-version",
13421+
reason: "python target runtime metadata",
13422+
});
13423+
expect(suite?.contextFiles).not.toContainEqual({
13424+
path: "runtime.txt",
13425+
reason: "python target runtime metadata",
13426+
});
1341513427
expect(suite?.tests).toEqual([{ path: "test_app.py", command: "pytest" }]);
1341613428
});
1341713429

13430+
it("threads Python runtime metadata into standalone pytest suites", async () => {
13431+
const root = await fixtureRoot("clawpatch-python-test-runtime-context-");
13432+
await writeFixture(root, "pyproject.toml", '[project]\nname = "runtime-tests"\n');
13433+
await writeFixture(root, ".python-version", "3.14\n");
13434+
await writeFixture(root, "runtime.txt", "python-3.14\n");
13435+
await writeFixture(
13436+
root,
13437+
"tests/test_pep758.py",
13438+
[
13439+
"def test_pep758_exception_group():",
13440+
" try:",
13441+
" int('x')",
13442+
" except TypeError, ValueError:",
13443+
" assert True",
13444+
"",
13445+
].join("\n"),
13446+
);
13447+
13448+
const project = await detectProject(root);
13449+
const result = await mapFeatures(root, project, []);
13450+
const suite = result.features.find((feature) => feature.title === "Python test suite tests");
13451+
13452+
expect(suite?.contextFiles).toContainEqual({
13453+
path: ".python-version",
13454+
reason: "python target runtime metadata",
13455+
});
13456+
expect(suite?.contextFiles).toContainEqual({
13457+
path: "runtime.txt",
13458+
reason: "python target runtime metadata",
13459+
});
13460+
expect(suite?.ownedFiles).toEqual([{ path: "tests/test_pep758.py", reason: "pytest file" }]);
13461+
expect(suite?.tests).toEqual([{ path: "tests/test_pep758.py", command: "pytest" }]);
13462+
});
13463+
1341813464
it("maps Flask routes under web source roots", async () => {
1341913465
const root = await fixtureRoot("clawpatch-python-flask-routes-");
1342013466
await writeFixture(root, "requirements.txt", "Flask\npytest\n");

src/mappers/python.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export async function pythonSeeds(root: string): Promise<FeatureSeed[]> {
190190
});
191191
}
192192

193-
for (const test of standaloneTestSuites(testFiles, testCommand)) {
193+
for (const test of standaloneTestSuites(testFiles, testCommand, runtimeContextFiles)) {
194194
seeds.push(test);
195195
}
196196

@@ -1666,7 +1666,11 @@ function fastApiRouteTrustBoundaries(route: FastApiRoute): FeatureSeed["trustBou
16661666
return boundaries;
16671667
}
16681668

1669-
function standaloneTestSuites(testFiles: string[], command: string | null): FeatureSeed[] {
1669+
function standaloneTestSuites(
1670+
testFiles: string[],
1671+
command: string | null,
1672+
runtimeContextFiles: SeedFileRef[],
1673+
): FeatureSeed[] {
16701674
if (testFiles.length === 0) {
16711675
return [];
16721676
}
@@ -1685,7 +1689,7 @@ function standaloneTestSuites(testFiles: string[], command: string | null): Feat
16851689
route: null,
16861690
command: null,
16871691
ownedFiles: group.files.map((path) => ({ path, reason: "pytest file" })),
1688-
contextFiles: [],
1692+
contextFiles: [...runtimeContextFiles],
16891693
tests: group.files.map((path) => ({ path, command })),
16901694
tags: ["python", "test"],
16911695
trustBoundaries: [],

0 commit comments

Comments
 (0)