From ae524a736cf3d08e0f041d020b94f83a17a77966 Mon Sep 17 00:00:00 2001 From: Dmitry Khalanskiy Date: Mon, 25 Oct 2021 13:56:08 +0300 Subject: [PATCH] Don't lose reported exceptions if the test body has thrown --- kotlinx-coroutines-test/common/src/TestBuilders.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kotlinx-coroutines-test/common/src/TestBuilders.kt b/kotlinx-coroutines-test/common/src/TestBuilders.kt index 4ecf8ce575..cdc4592ddf 100644 --- a/kotlinx-coroutines-test/common/src/TestBuilders.kt +++ b/kotlinx-coroutines-test/common/src/TestBuilders.kt @@ -231,6 +231,13 @@ public fun runTest( } } deferred.getCompletionExceptionOrNull()?.let { + try { + testScope.cleanupTestCoroutines() + } catch (e: UncompletedCoroutinesError) { + // it's normal that some jobs are not completed if the test body has failed, won't clutter the output + } catch (e: Throwable) { + e.printStackTrace() + } throw it } testScope.cleanupTestCoroutines()