Skip to content

Flaky unit-test collection: KeyError importing feast.infra.mcp_servers.mcp_server under pytest -n #6633

Description

@larrysingleton007

Expected Behavior

make test-python-unit (pytest with -n / xdist) collects sdk/python/tests/unit/infra/feature_servers/test_mcp_server.py reliably.

Current Behavior

Intermittently, parallel unit-test collection fails on an xdist worker while importing the MCP server package, which aborts the whole session:

ERROR collecting tests/unit/infra/feature_servers/test_mcp_server.py
sdk/python/tests/unit/infra/feature_servers/test_mcp_server.py:8: in <module>
    from feast.infra.mcp_servers.mcp_config import McpFeatureServerConfig
sdk/python/feast/infra/mcp_servers/__init__.py:4: in <module>
    from .mcp_server import add_mcp_support_to_app
<frozen importlib._bootstrap>:946: in _load_unlocked
E   KeyError: 'feast.infra.mcp_servers.mcp_server'

The tests pass in isolation, so this surfaces as a flaky unit-test-python job failure (seen recently on unit-test-python (3.12, ubuntu-latest)).

Root cause: feast/infra/mcp_servers/mcp_server.py imports feast.feature_store.FeatureStore at module load but uses it only for a type annotation on add_mcp_support_to_app. Because the package __init__.py eagerly imports mcp_server, importing feast.infra.mcp_servers pulls in the whole feature_store import graph. Under parallel collection that heavy import races with an in-progress feature_store import; the partially-initialized mcp_server module is cleaned up, and the outer import's sys.modules.pop("feast.infra.mcp_servers.mcp_server") raises KeyError.

Steps to reproduce

Ordering-dependent, so not reliably reproducible in isolation; it surfaces under the full parallel unit-test run (make test-python-unit, pytest -n). Isolated collection (pytest --collect-only .../test_mcp_server.py) always succeeds.

Specifications

  • Version: master (module unchanged through 0.65.x)
  • Platform: CI unit-test-python (3.12, ubuntu-latest)
  • Subsystem: infra/mcp_servers, unit-test collection

Possible Solution

Move the FeatureStore import in mcp_server.py under TYPE_CHECKING (it is only a type annotation), so importing mcp_server no longer drags in the feature_store graph. I have a fix ready and will open a PR referencing this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions