mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fd6fad967d
commit
41e3009702
+13
-1
@@ -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<C
|
||||
@Service
|
||||
class MyService(val scope: CoroutineScope)
|
||||
|
||||
val scope = ApplicationManager.getApplication().service<MyService>().scope.childScope(name)
|
||||
var unhandledException: Throwable? = null
|
||||
val handler = CoroutineExceptionHandler { _, exception ->
|
||||
unhandledException = exception
|
||||
throw exception
|
||||
}
|
||||
val scope = ApplicationManager.getApplication().service<MyService>().scope.childScope(name, handler)
|
||||
initialized(scope) {
|
||||
scope.coroutineContext.job.cancelAndJoin()
|
||||
scope.cancel()
|
||||
unhandledException?.let {
|
||||
throw it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user