diff --git a/python/junit5Tests-framework/intellij.python.community.junit5Tests.framework.iml b/python/junit5Tests-framework/intellij.python.community.junit5Tests.framework.iml
index d2619ec7f59b..b658b3b0829a 100644
--- a/python/junit5Tests-framework/intellij.python.community.junit5Tests.framework.iml
+++ b/python/junit5Tests-framework/intellij.python.community.junit5Tests.framework.iml
@@ -31,5 +31,6 @@
+
\ No newline at end of file
diff --git a/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/TestTools.kt b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/TestTools.kt
index b135860b230a..5f8fcbd0f6da 100644
--- a/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/TestTools.kt
+++ b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/TestTools.kt
@@ -1,10 +1,17 @@
-// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.junit5Tests
import com.intellij.execution.configurations.PathEnvironmentVariableUtil
+import com.intellij.openapi.application.EDT
+import com.intellij.openapi.application.writeIntentReadAction
+import com.intellij.openapi.fileEditor.FileEditorManager
+import com.intellij.openapi.fileEditor.impl.EditorHistoryManager
+import com.intellij.openapi.project.Project
import com.intellij.openapi.util.SystemInfoRt
import com.jetbrains.python.PythonBinary
import com.jetbrains.python.Result
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
import org.junit.jupiter.api.Assertions
import kotlin.io.path.Path
@@ -28,4 +35,18 @@ fun Result<*, *>.assertFail() {
is Result.Failure -> Assertions.assertNotNull(this.error, "No error")
is Result.Success -> Assertions.fail("Unexpected success: ${this.result}")
}
+}
+
+/**
+ * Close all files opened in [project]. Might be useful to call in `finally` or in [org.junit.jupiter.api.AfterEach]
+ */
+suspend fun closeAllFiles(project: Project): Unit = withContext(Dispatchers.EDT) {
+ writeIntentReadAction {
+ FileEditorManager.getInstance(project).apply {
+ for (openFile in openFiles) {
+ closeFile(openFile)
+ }
+ }
+ }
+ EditorHistoryManager.getInstance(project).removeAllFiles()
}
\ No newline at end of file