def test_model_checkpoint_link_checkpoint_relative_path(tmp_path, monkeypatch):
    """Test that linking a checkpoint works with relative paths."""
    trainer = Mock()
    monkeypatch.chdir(tmp_path)

    folder = Path("x/z/z")
    folder.mkdir(parents=True)
    file = folder / "file"
    file.touch()
    link = folder / "link"
    ModelCheckpoint._link_checkpoint(trainer, filepath=str(file.absolute()), linkpath=str(link.absolute()))
    assert os.path.islink(link)
    assert Path(os.readlink(link)) == file.relative_to(folder)
    assert not os.path.isabs(os.readlink(link))
Test that linking a checkpoint works with relative paths.
tests/tests_pytorch/checkpointing/test_model_checkpoint.py