From 951f3300ed3f8a1797bde89d0352d6490ce2cd2f Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Mon, 7 Aug 2023 14:15:01 +0200 Subject: [PATCH] fix(tools): Keep the original Python environment when idf_tools.py tests are run --- tools/test_idf_tools/test_idf_tools_python_env.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/test_idf_tools/test_idf_tools_python_env.py b/tools/test_idf_tools/test_idf_tools_python_env.py index 24bce9d6bf..8a47a00939 100644 --- a/tools/test_idf_tools/test_idf_tools_python_env.py +++ b/tools/test_idf_tools/test_idf_tools_python_env.py @@ -28,6 +28,7 @@ except ImportError: IDF_PATH = os.environ.get('IDF_PATH', '../..') TOOLS_DIR = os.environ.get('IDF_TOOLS_PATH') or os.path.expanduser(idf_tools.IDF_TOOLS_PATH_DEFAULT) PYTHON_DIR = os.path.join(TOOLS_DIR, 'python_env') +PYTHON_DIR_BACKUP = tempfile.mkdtemp() REQ_SATISFIED = 'Python requirements are satisfied' REQ_CORE = '- {}'.format(os.path.join(IDF_PATH, 'tools', 'requirements', 'requirements.core.txt')) REQ_GDBGUI = '- {}'.format(os.path.join(IDF_PATH, 'tools', 'requirements', 'requirements.gdbgui.txt')) @@ -40,6 +41,17 @@ idf_tools.global_idf_path = IDF_PATH idf_tools.global_idf_tools_path = TOOLS_DIR +def setUpModule(): # type: () -> None + shutil.rmtree(PYTHON_DIR_BACKUP) + shutil.move(PYTHON_DIR, PYTHON_DIR_BACKUP) + + +def tearDownModule(): # type: () -> None + if os.path.isdir(PYTHON_DIR): + shutil.rmtree(PYTHON_DIR) + shutil.move(PYTHON_DIR_BACKUP, PYTHON_DIR) + + class BasePythonInstall(unittest.TestCase): def run_tool(self, cmd): # type: (List[str]) -> str ret = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=300) @@ -262,8 +274,6 @@ class TestCheckPythonDependencies(BasePythonInstall): def tearDown(self): # type: () -> None shutil.copyfile(self.backup_constraint_file, self.constraint_file) - if os.path.isdir(PYTHON_DIR): - shutil.rmtree(PYTHON_DIR) def test_check_python_dependencies(self): # type: () -> None # Prepare artificial constraints file containing packages from