def _get_custom_import(torch_installed: bool):
    """
    Simulate absence of PyTorch installation depending on the input flag.

    Args:
        torch_installed (bool): Flag indicating whether or not PyTorch is installed.

    Returns:
        Generator: Parametrized `_custom_import()` function.

    """
    # Store the original __import__ function
    original_import = builtins.__import__

    def _custom_import(module_name: str, *args, **kwargs) -> ModuleType:
        """
        If `torch_installed` is False, act as if PyTorch is not installed.
        """
        if module_name == "torch" and not torch_installed:
            raise ImportError('No module named "torch.')

        return original_import(module_name, *args, **kwargs)

    try:
        # Replace the built-in __import__ function
        builtins.__import__ = _custom_import

        yield
    except Exception:
        # Restore the original import function
        builtins.__import__ = original_import

        raise
    finally:
        # Restore the original import function
        builtins.__import__ = original_import

    Simulate absence of PyTorch installation depending on the input flag.

    Args:
        torch_installed (bool): Flag indicating whether or not PyTorch is installed.

    Returns:
        Generator: Parametrized `_custom_import()` function.

    
llama-index-integrations/readers/llama-index-readers-file/tests/test_image_vision_llm.py