From 41e3009702a975aee2fc5a82d2bf7ed645ada5aa Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Thu, 12 Feb 2026 22:00:26 +0100 Subject: [PATCH] testFramework [python]: Fail test when a application scope fixture throws exception. Currently, exceptions thrown by fixture teardowns are ignored as they are thrown in background scope. We collect them and report them GitOrigin-RevId: bb0c777926994371a056f52cb1de80893691a438 --- .../python/junit5Tests/framework/fixtures.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/fixtures.kt b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/fixtures.kt index 9f87d60893a8..4259b2406e8f 100644 --- a/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/fixtures.kt +++ b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/fixtures.kt @@ -10,8 +10,11 @@ import com.intellij.psi.PsiDirectory import com.intellij.psi.PsiFile import com.intellij.testFramework.junit5.fixture.TestFixture import com.intellij.testFramework.junit5.fixture.testFixture +import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.cancel +import kotlinx.coroutines.cancelAndJoin +import kotlinx.coroutines.job import org.jetbrains.annotations.TestOnly import java.nio.file.Path import java.util.UUID @@ -25,9 +28,18 @@ fun applicationScope(name: String = UUID.randomUUID().toString()): TestFixture().scope.childScope(name) + var unhandledException: Throwable? = null + val handler = CoroutineExceptionHandler { _, exception -> + unhandledException = exception + throw exception + } + val scope = ApplicationManager.getApplication().service().scope.childScope(name, handler) initialized(scope) { + scope.coroutineContext.job.cancelAndJoin() scope.cancel() + unhandledException?.let { + throw it + } } }