From 5484db34f9c7d5bd0771bf88f1867daa90e5ce1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20Tr=E1=BB=8Dng=20H=E1=BA=A3i?= <41283691+hainenber@users.noreply.github.com> Date: Mon, 6 Jan 2025 23:45:45 +0700 Subject: [PATCH] chore: replace `imp` built-in module usage for future Python3.12 usage (#31622) Signed-off-by: hainenber Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com> --- tests/integration_tests/base_tests.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration_tests/base_tests.py b/tests/integration_tests/base_tests.py index f922b3796..5ddda0c59 100644 --- a/tests/integration_tests/base_tests.py +++ b/tests/integration_tests/base_tests.py @@ -18,7 +18,7 @@ """Unit tests for Superset""" from datetime import datetime -import imp +from importlib.util import find_spec from contextlib import contextmanager from typing import Any, Union, Optional from unittest.mock import Mock, patch, MagicMock @@ -256,11 +256,11 @@ class SupersetTestCase(TestCase): return db.session.query(SqlaTable).filter_by(id=table_id).one() @staticmethod - def is_module_installed(module_name): + def is_module_installed(module_name: str) -> bool: try: - imp.find_module(module_name) - return True - except ImportError: + spec = find_spec(module_name) + return spec is not None + except (ModuleNotFoundError, ValueError, TypeError, ImportError): return False def get_or_create(self, cls, criteria, **kwargs):