code: def test_storage_driver_client(monkeypatch):
      class MockedDriver(StorageDriver):
          @staticmethod
          def build_client(_):
              return {"built": True, "passed": False}
  
          def delete_object(self, object_name: str):
              ...
  
          def download_object(
              self, object_name: str, destination_path: str
          ):
              ...
  
          def exists(self, object_name: str) -> bool:
              ...
  
          def upload_object(self, file_path: str, object_name: str):
              ...
  
          def get_object_uri(
              self, object_name: str, sub_part: Optional[str] = None
          ):
              ...
  
          def iterate_objects(self, prefix: Optional[str] = None):
              ...
  
      # the storage provider should not build the client
      # since passed at instantiation
      settings = StorageDriverSettings(bucket="bucket")
      driver = MockedDriver(
          settings, client={"built": False, "passed": True}
      )
      assert settings.lazy_driver is False
      assert driver._client is not None
      assert (
          driver._client
          == driver.client
          == {"built": False, "passed": True}
      )
  
      # the storage provider should build the client at init
      driver = MockedDriver(settings)
      assert settings.lazy_driver is False
      assert driver._client is not None
      assert (
          driver._client
          == driver.client
          == {"built": True, "passed": False}
      )
  
      monkeypatch.setenv("MODELKIT_LAZY_DRIVER", True)
      # the storage provider should not build the client eagerly nor store it
      # since MODELKIT_LAZY_DRIVER is set
      settings = StorageDriverSettings(bucket="bucket")
      driver = MockedDriver(settings)
      assert settings.lazy_driver is True
      assert driver._client is None
      # the storage provider builds it on-the-fly when accessed via the `client` property
      assert driver.client == {"built": True, "passed": False}
      # but does not store it
      assert driver._client is None
  
      # the storage provider should not build any client but use the one passed
      # at instantiation
      driver = MockedDriver(
          settings, client={"built": False, "passed": True}
      )
      assert driver._client is not None
      assert (
          driver._client
          == driver.client
          == {"built": False, "passed": True}
      )
  
file_path: modelkit/tests/assets/test_drivers.py
imports: import os
  import pickle
  import tempfile
  from typing import Optional
  from modelkit.assets.drivers.abc import StorageDriver, StorageDriverSettings
  from modelkit.assets.drivers.local import LocalStorageDriver
  from tests import TEST_DIR
  from tests.conftest import skip_unless
label_desc: Use image node_id 12 for calling a global function with example usage: test_storage_driver_client(monkeypatch) and returns: dict