def test_trainer_save_checkpoint_storage_options(tmp_path, xla_available):
    """This test validates that storage_options argument is properly passed to ``CheckpointIO``"""
    model = BoringModel()
    trainer = Trainer(
        default_root_dir=tmp_path,
        fast_dev_run=True,
        enable_checkpointing=False,
    )
    trainer.fit(model)
    instance_path = tmp_path / "path.ckpt"
    instance_storage_options = "my instance storage options"

    with mock.patch("lightning.fabric.plugins.io.torch_io.TorchCheckpointIO.save_checkpoint") as io_mock:
        trainer.save_checkpoint(instance_path, storage_options=instance_storage_options)
        io_mock.assert_called_with(ANY, instance_path, storage_options=instance_storage_options)
        trainer.save_checkpoint(instance_path)
        io_mock.assert_called_with(ANY, instance_path, storage_options=None)

    checkpoint_mock = Mock()
    with (
        mock.patch.object(trainer.strategy, "save_checkpoint") as save_mock,
        mock.patch.object(trainer._checkpoint_connector, "dump_checkpoint", return_value=checkpoint_mock) as dump_mock,
    ):
        trainer.save_checkpoint(instance_path, True)
        dump_mock.assert_called_with(True)
        save_mock.assert_called_with(checkpoint_mock, instance_path, storage_options=None)
        trainer.save_checkpoint(instance_path, False, instance_storage_options)
        dump_mock.assert_called_with(False)
        save_mock.assert_called_with(checkpoint_mock, instance_path, storage_options=instance_storage_options)

    torch_checkpoint_io = TorchCheckpointIO()
    with pytest.raises(
        TypeError,
        match=r"`Trainer.save_checkpoint\(..., storage_options=...\)` with `storage_options` arg"
        f" is not supported for `{torch_checkpoint_io.__class__.__name__}`. Please implement your custom `CheckpointIO`"
        " to define how you'd like to use `storage_options`.",
    ):
        torch_checkpoint_io.save_checkpoint({}, instance_path, storage_options=instance_storage_options)
    xla_checkpoint_io = XLACheckpointIO()
    with pytest.raises(
        TypeError,
        match=r"`Trainer.save_checkpoint\(..., storage_options=...\)` with `storage_options` arg"
        f" is not supported for `{xla_checkpoint_io.__class__.__name__}`. Please implement your custom `CheckpointIO`"
        " to define how you'd like to use `storage_options`.",
    ):
        xla_checkpoint_io.save_checkpoint({}, instance_path, storage_options=instance_storage_options)
This test validates that storage_options argument is properly passed to ``CheckpointIO``
tests/tests_pytorch/checkpointing/test_trainer_checkpoint.py