def test_configure_callbacks_hook_multiple_calls(tmp_path):
    """Test that subsequent calls to `configure_callbacks` do not change the callbacks list."""
    model_callback_mock = Mock(spec=Callback, model=Callback())

    class TestModel(BoringModel):
        def configure_callbacks(self):
            return model_callback_mock

    model = TestModel()
    trainer = Trainer(default_root_dir=tmp_path, fast_dev_run=True, enable_checkpointing=False)

    callbacks_before_fit = trainer.callbacks.copy()
    assert callbacks_before_fit

    trainer.fit(model)
    callbacks_after_fit = trainer.callbacks.copy()
    assert callbacks_after_fit == callbacks_before_fit + [model_callback_mock]

    for fn in ("test", "validate"):
        trainer_fn = getattr(trainer, fn)
        trainer_fn(model)

        callbacks_after = trainer.callbacks.copy()
        assert callbacks_after == callbacks_after_fit

        trainer_fn(model)
        callbacks_after = trainer.callbacks.copy()
        assert callbacks_after == callbacks_after_fit
Test that subsequent calls to `configure_callbacks` do not change the callbacks list.
tests/tests_pytorch/callbacks/test_callbacks.py