Skip to content

Commit 4940f1d

Browse files
authored
preserve muted and flaky annotations for failed spock tests (fixes #1303, via #1330)
1 parent eaf7a3e commit 4940f1d

3 files changed

Lines changed: 66 additions & 5 deletions

File tree

allure-spock2/src/main/java/io/qameta/allure/spock2/AllureSpock2.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,26 @@ public void error(final ErrorInfo error) {
311311
if (Objects.isNull(uuid)) {
312312
return;
313313
}
314-
getLifecycle().updateTest(
315-
testKey(uuid), testResult -> testResult
316-
.setStatus(getStatus(error.getException()).orElse(null))
317-
.setStatusDetails(getStatusDetails(error.getException()).orElse(null))
318-
);
314+
final Throwable exception = error.getException();
315+
getLifecycle().updateTest(testKey(uuid), testResult -> {
316+
testResult.setStatus(getStatus(exception).orElse(null));
317+
318+
final StatusDetails details = getStatusDetails(exception).orElse(null);
319+
if (Objects.isNull(details)) {
320+
return;
321+
}
322+
// merge the exception details into the existing status details so that
323+
// the flaky/muted flags set in beforeIteration are not overwritten
324+
final StatusDetails current = testResult.getStatusDetails();
325+
if (Objects.isNull(current)) {
326+
testResult.setStatusDetails(details);
327+
} else {
328+
current.setMessage(details.getMessage())
329+
.setTrace(details.getTrace())
330+
.setActual(details.getActual())
331+
.setExpected(details.getExpected());
332+
}
333+
});
319334
}
320335

321336
/**

allure-spock2/src/test/groovy/io/qameta/allure/spock2/AllureSpock2Test.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.qameta.allure.spock2.samples.DataDrivenTest;
3232
import io.qameta.allure.spock2.samples.DerivedSpec;
3333
import io.qameta.allure.spock2.samples.FailedTest;
34+
import io.qameta.allure.spock2.samples.FailedTestWithAnnotations;
3435
import io.qameta.allure.spock2.samples.FixturesTest;
3536
import io.qameta.allure.spock2.samples.HelloSpockSpec;
3637
import io.qameta.allure.spock2.samples.OneTest;
@@ -356,6 +357,21 @@ void shouldProcessMutedAnnotation() {
356357
);
357358
}
358359

360+
@Test
361+
void shouldKeepFlakyAndMutedForFailedTest() {
362+
final AllureResults results = runClasses(FailedTestWithAnnotations.class);
363+
assertThat(results.getTestResults())
364+
.extracting(
365+
TestResult::getName,
366+
TestResult::getStatus,
367+
tr -> tr.getStatusDetails().isFlaky(),
368+
tr -> tr.getStatusDetails().isMuted()
369+
)
370+
.containsExactly(
371+
tuple("failedTest", Status.FAILED, true, true)
372+
);
373+
}
374+
359375
@Test
360376
void shouldSetDisplayName() {
361377
final AllureResults results = runClasses(OneTest.class);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2016-2026 Qameta Software Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.spock2.samples
17+
18+
import io.qameta.allure.Flaky
19+
import io.qameta.allure.Muted
20+
import spock.lang.Specification
21+
22+
class FailedTestWithAnnotations extends Specification {
23+
24+
@Flaky
25+
@Muted
26+
def "failedTest"() {
27+
expect:
28+
false
29+
}
30+
}

0 commit comments

Comments
 (0)