def test_validate_user_settings():
    """Test that the environment can validate the number of devices and nodes set in Fabric/Trainer."""
    env = SLURMEnvironment()
    env.validate_settings(num_devices=4, num_nodes=2)

    with pytest.raises(ValueError, match="the number of tasks per node configured .* does not match"):
        env.validate_settings(num_devices=2, num_nodes=2)

    with pytest.raises(ValueError, match="the number of nodes configured in SLURM .* does not match"):
        env.validate_settings(num_devices=4, num_nodes=1)

    # in interactive mode, validation is skipped becauses processes get launched by Fabric/Trainer, not SLURM
    with mock.patch(
        "lightning.fabric.plugins.environments.slurm.SLURMEnvironment.job_name", return_value="interactive"
    ):
        env = SLURMEnvironment()
        env.validate_settings(num_devices=4, num_nodes=1)  # no error
Test that the environment can validate the number of devices and nodes set in Fabric/Trainer.
tests/tests_fabric/plugins/environments/test_slurm.py