Skip to content

Commit 80b742e

Browse files
committed
fix: correct update of test run results when suite teardown fails or is skipped during suite teardown
Unfortunately, if a test has already failed but it is subsequently skipped in the teardown, the error status of VSCode is not set because the skipped status has a lower priority than the failed status. This is a VSCode problem and I can't change it at the moment.
1 parent 15ef139 commit 80b742e

File tree

2 files changed

+89
-10
lines changed

2 files changed

+89
-10
lines changed

packages/debugger/src/robotcode/debugger/listeners.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def end_suite(self, name: str, attributes: Dict[str, Any]) -> None:
6060
),
6161
)
6262

63+
self.failed_keywords = None
64+
6365
def start_test(self, name: str, attributes: Dict[str, Any]) -> None:
6466
self.failed_keywords = None
6567

@@ -287,8 +289,36 @@ def enqueue(item: Union[running.TestSuite, running.TestCase]) -> Iterator[str]:
287289

288290
self._event_sended = True
289291

290-
def end_suite(self, data: running.TestSuite, result: result.TestSuite) -> None:
291-
pass
292+
def end_suite(self, data: running.TestSuite, suite_result: result.TestSuite) -> None:
293+
def report_status(item: Union[result.TestSuite, result.TestCase], message: str) -> None:
294+
if isinstance(item, result.TestCase):
295+
Debugger.instance().send_event(
296+
self,
297+
Event(
298+
event="robotSetFailed",
299+
body=RobotExecutionEventBody(
300+
type="test",
301+
attributes={
302+
"longname": item.longname,
303+
"status": str(item.status),
304+
"elapsedtime": item.elapsedtime,
305+
"source": str(item.source),
306+
"lineno": item.lineno,
307+
"message": item.message,
308+
},
309+
id=f"{item.source or ''};{item.longname or ''}"
310+
+ (f";{item.lineno or 0}" if isinstance(item, result.TestCase) else ""),
311+
),
312+
),
313+
)
314+
if isinstance(item, result.TestSuite):
315+
for r in item.suites:
316+
report_status(r, message)
317+
for r in item.tests:
318+
report_status(r, message)
319+
320+
if data.teardown and suite_result.teardown.status in ["FAIL", "SKIP"]:
321+
report_status(suite_result, message=suite_result.message)
292322

293323
def start_test(self, data: running.TestCase, result: result.TestCase) -> None:
294324
pass

vscode-client/testcontrollermanager.ts

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class TestControllerManager {
151151
public readonly debugManager: DebugManager,
152152
public readonly outputChannel: vscode.OutputChannel,
153153
) {
154-
this.testController = vscode.tests.createTestController("robotCode.RobotFramework", "RobotFramework");
154+
this.testController = vscode.tests.createTestController("robotCode.RobotFramework", "Robot Framework");
155155

156156
this.testController.resolveHandler = async (item) => {
157157
await this.refresh(item);
@@ -264,7 +264,6 @@ export class TestControllerManager {
264264
this.TestRunExited(event.session.configuration.runId);
265265
break;
266266
}
267-
268267
case "robotStarted": {
269268
this.OnRobotStartedEvent(event.session.configuration.runId, event.body as RobotExecutionEvent);
270269
break;
@@ -273,6 +272,10 @@ export class TestControllerManager {
273272
this.OnRobotEndedEvent(event.session.configuration.runId, event.body as RobotExecutionEvent);
274273
break;
275274
}
275+
case "robotSetFailed": {
276+
this.OnRobotSetFailed(event.session.configuration.runId, event.body as RobotExecutionEvent);
277+
break;
278+
}
276279
case "robotEnqueued": {
277280
this.TestItemEnqueued(event.session.configuration.runId, event.body?.items);
278281
break;
@@ -1202,20 +1205,64 @@ export class TestControllerManager {
12021205
}
12031206
}
12041207

1208+
private OnRobotSetFailed(runId: string | undefined, event: RobotExecutionEvent) {
1209+
switch (event.type) {
1210+
case "suite":
1211+
case "test":
1212+
this.TestItemSetFailed(runId, event);
1213+
break;
1214+
default:
1215+
// do nothing
1216+
break;
1217+
}
1218+
}
1219+
1220+
private TestItemSetFailed(runId: string | undefined, event: RobotExecutionEvent) {
1221+
if (runId === undefined || event.attributes?.longname === undefined) return;
1222+
1223+
const run = this.testRuns.get(runId);
1224+
1225+
if (run !== undefined) {
1226+
const item = this.findTestItemById(event.id);
1227+
if (item) {
1228+
const message = new vscode.TestMessage(event.attributes?.message ?? "");
1229+
1230+
if (event.attributes.source) {
1231+
message.location = new vscode.Location(
1232+
vscode.Uri.file(event.attributes.source),
1233+
new vscode.Range(
1234+
new vscode.Position((event.attributes.lineno ?? 1) - 1, 0),
1235+
new vscode.Position(event.attributes.lineno ?? 1, 0),
1236+
),
1237+
);
1238+
}
1239+
1240+
if (event.attributes.status === "SKIP") {
1241+
run.skipped(item);
1242+
} else if (event.attributes.status === "FAIL") {
1243+
run.failed(item, message, event.attributes.elapsedtime);
1244+
} else if (event.attributes.status === "ERROR") {
1245+
run.errored(item, message, event.attributes.elapsedtime);
1246+
}
1247+
}
1248+
}
1249+
}
1250+
12051251
private TestItemEnded(runId: string | undefined, event: RobotExecutionEvent) {
12061252
if (runId === undefined || event.attributes?.longname === undefined) return;
12071253

12081254
const run = this.testRuns.get(runId);
12091255

12101256
if (run !== undefined) {
12111257
const item = this.findTestItemById(event.id);
1258+
12121259
if (item !== undefined) {
12131260
switch (event.attributes.status) {
12141261
case "PASS":
1215-
run.passed(item, event.attributes.elapsedtime);
1262+
if (!item?.canResolveChildren) run.passed(item, event.attributes.elapsedtime);
12161263
break;
12171264
case "SKIP":
1218-
run.skipped(item);
1265+
if (!item?.canResolveChildren) run.skipped(item);
12191266
break;
12201267
default:
12211268
{
@@ -1256,10 +1303,12 @@ export class TestControllerManager {
12561303
messages.push(message);
12571304
}
12581305

1259-
if (event.attributes.status === "FAIL") {
1260-
run.failed(item, messages, event.attributes.elapsedtime);
1261-
} else {
1262-
run.errored(item, messages, event.attributes.elapsedtime);
1306+
if (!item?.canResolveChildren) {
1307+
if (event.attributes.status === "FAIL") {
1308+
run.failed(item, messages, event.attributes.elapsedtime);
1309+
} else {
1310+
run.errored(item, messages, event.attributes.elapsedtime);
1311+
}
12631312
}
12641313
}
12651314
break;

0 commit comments

Comments
 (0)