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 + } } }