def test_multiple_optimizers_automatic_optimization_raises():
    """Test that multiple optimizers in automatic optimization is not allowed."""

    class TestModel(BoringModel):
        def training_step(self, batch, batch_idx, optimizer_idx):
            return super().training_step(batch, batch_idx)

    model = TestModel()
    model.automatic_optimization = True

    trainer = pl.Trainer(logger=False, enable_checkpointing=False)
    with pytest.raises(RuntimeError, match="Remove the `optimizer_idx` argument from `training_step`"):
        trainer.fit(model)

    class TestModel(BoringModel):
        def configure_optimizers(self):
            return torch.optim.Adam(self.parameters()), torch.optim.Adam(self.parameters())

    model = TestModel()
    model.automatic_optimization = True

    trainer = pl.Trainer(logger=False, enable_checkpointing=False)
    with pytest.raises(RuntimeError, match="multiple optimizers is only supported with manual optimization"):
        trainer.fit(model)
Test that multiple optimizers in automatic optimization is not allowed.
tests/tests_pytorch/trainer/optimization/test_multiple_optimizers.py