def test_factory_registrations_preserved(reference_factory_registrations):
    """Test that all factory registrations from the reference file are still present."""
    # Ensure the registry is populated
    registry.ensure_populated()

    # Get all factory registrations
    all_factories = registry.factories.get_all()

    # Initialize our data structure to store current factory registrations
    current_registrations = {}

    # Process factory registrations
    for name, func in all_factories.items():
        # Store information about each factory
        try:
            module_name = func.__module__
        except (AttributeError, TypeError):
            # For Cython functions, just use a placeholder
            module_name = str(func).split()[1].split(".")[0]

        try:
            func_name = func.__qualname__
        except (AttributeError, TypeError):
            # For Cython functions, use the function's name
            func_name = (
                func.__name__
                if hasattr(func, "__name__")
                else str(func).split()[1].split(".")[-1]
            )

        current_registrations[name] = {
            "name": name,
            "module": module_name,
            "function": func_name,
        }

    # Check for missing registrations
    missing_registrations = set(reference_factory_registrations.keys()) - set(
        current_registrations.keys()
    )
    assert (
        not missing_registrations
    ), f"Missing factory registrations: {', '.join(sorted(missing_registrations))}"

    # Check for new registrations (not an error, but informative)
    new_registrations = set(current_registrations.keys()) - set(
        reference_factory_registrations.keys()
    )
    if new_registrations:
        # This is not an error, just informative
        print(
            f"New factory registrations found: {', '.join(sorted(new_registrations))}"
        )
Test that all factory registrations from the reference file are still present.
spacy/tests/test_factory_registrations.py