def test_load_external_callbacks():
    """Test that the connector collects Callback instances from factories registered through entry points."""

    def factory_no_callback():
        return []

    def factory_one_callback():
        return ExternalCallback()

    def factory_one_callback_list():
        return [ExternalCallback()]

    def factory_multiple_callbacks_list():
        return [ExternalCallback(), ExternalCallback()]

    with _make_entry_point_query_mock(factory_no_callback):
        callbacks = _load_external_callbacks("lightning.pytorch.callbacks_factory")
    assert callbacks == []

    with _make_entry_point_query_mock(factory_one_callback):
        callbacks = _load_external_callbacks("lightning.pytorch.callbacks_factory")
    assert isinstance(callbacks[0], ExternalCallback)

    with _make_entry_point_query_mock(factory_one_callback_list):
        callbacks = _load_external_callbacks("lightning.pytorch.callbacks_factory")
    assert isinstance(callbacks[0], ExternalCallback)

    with _make_entry_point_query_mock(factory_multiple_callbacks_list):
        callbacks = _load_external_callbacks("lightning.pytorch.callbacks_factory")
    assert isinstance(callbacks[0], ExternalCallback)
    assert isinstance(callbacks[1], ExternalCallback)
Test that the connector collects Callback instances from factories registered through entry points.
tests/tests_fabric/utilities/test_registry.py