From a1d1780c22dd52f85d7d86ac3915173d2552a0a3 Mon Sep 17 00:00:00 2001 From: monsurcodes Date: Sat, 13 Dec 2025 20:09:14 +0530 Subject: [PATCH] Add script to install required Python modules for tests --- ...cript_install_required_modules_for_test.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Tests/script_install_required_modules_for_test.py diff --git a/Tests/script_install_required_modules_for_test.py b/Tests/script_install_required_modules_for_test.py new file mode 100644 index 0000000..37fcac0 --- /dev/null +++ b/Tests/script_install_required_modules_for_test.py @@ -0,0 +1,55 @@ +import subprocess +import sys +import importlib +import os + +def install_module(module_name): + """Install a Python module using pip.""" + + pip = "" + if os.name == 'nt': + pip = "pip" + else: + pip = "pip3" + + try: + subprocess.check_call([sys.executable, "-m", pip, "install", module_name]) + return True + except subprocess.CalledProcessError as e: + print(f"[ERROR] Failed to install module {module_name}: {e}") + + return False + +def check_module_installed(module_name): + """Check if a Python module is installed.""" + try: + importlib.import_module(module_name) + return True + except ImportError: + return False + +if __name__ == "__main__": + required_modules = [ + "starlette", + "fastapi", + "aiohttp", + "flask", + "django", + ] + + for module in required_modules: + if not check_module_installed(module): + print(f"[INFO] Module {module} is not installed. Attempting to install...") + + if install_module(module): + print(f"[INFO] Rechecking installation of module: {module}") + else: + print(f"[ERROR] Installation attempt for module {module} failed.") + continue + + if not check_module_installed(module): + print(f"[ERROR] Module {module} could not be installed. Please install it manually.") + + print(f"[INFO] Module {module} is installed.") + + print("[INFO] All required modules are installed.")