From ee348c2a406c9b2e7f9172a6120ccca8816ecac1 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Sun, 15 Dec 2024 15:31:12 +0100 Subject: [PATCH] Python tests: Add pythons to the list of allowed roots. In tests, we check that no code access files outside so-called roots. Roots are usually project roots, but we might need to access files in python installation dirs (to access `black.exe`, `poetry.exe` and so on) We already fixed it for JUnit5 tests. We now fix it for the legacy `PyEnvTestCase` See `VfsRootAccess`. GitOrigin-RevId: 494e60d3d07b9d14b4001b7f37f4f5188d63c994 --- python/testSrc/com/jetbrains/env/PyEnvTestCase.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/python/testSrc/com/jetbrains/env/PyEnvTestCase.java b/python/testSrc/com/jetbrains/env/PyEnvTestCase.java index de1ebc7eaddc..9c02ef94575a 100644 --- a/python/testSrc/com/jetbrains/env/PyEnvTestCase.java +++ b/python/testSrc/com/jetbrains/env/PyEnvTestCase.java @@ -5,6 +5,8 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess; import com.intellij.testFramework.UsefulTestCase; import com.intellij.util.ArrayUtil; import com.intellij.util.ArrayUtilRt; @@ -236,8 +238,11 @@ public abstract class PyEnvTestCase { * @return list of pythons to run tests against */ @NotNull - protected List getPythonRoots() { - return getDefaultPythonRoots(); + protected List<@NotNull String> getPythonRoots() { + var roots = getDefaultPythonRoots(); + // It is ok to access these pythons + VfsRootAccess.allowRootAccess(myDisposable, ArrayUtil.toStringArray(roots)); + return roots; } private final Disposable myDisposable = Disposer.newDisposable();