def test_local_cross_device_checkpoint(tmpdir):
    """Test that the _CheckpointConnector can write local cross-device files or raises an error if fsspec<2025.5.0."""
    model = BoringModel()
    # hardcoding dir since `tmp_path` can be windows path
    trainer = Trainer(
        default_root_dir="memory://test_ckpt_for_fsspec", limit_train_batches=1, limit_val_batches=1, max_epochs=1
    )
    trainer.fit(model)
    # Simulate the behavior of fsspec when writing to a local file system but other device.
    with (
        mock.patch("os.rename", side_effect=OSError(errno.EXDEV, "Invalid cross-device link")),
        mock.patch("os.chmod", side_effect=PermissionError("Operation not permitted")),
    ):
        if fsspec.__version__ < "2025.5.0":
            with pytest.raises(
                RuntimeError,
                match=re.escape(
                    'Upgrade fsspec to enable cross-device local checkpoints: pip install "fsspec[http]>=2025.5.0"'
                ),
            ):
                trainer.save_checkpoint(tmpdir + "/test_ckpt_for_fsspec/hpc_ckpt.ckpt")
        else:
            trainer.save_checkpoint(tmpdir + "/test_ckpt_for_fsspec/hpc_ckpt.ckpt")
Test that the _CheckpointConnector can write local cross-device files or raises an error if fsspec<2025.5.0.
tests/tests_pytorch/trainer/connectors/test_checkpoint_connector.py