Skip to content

Backend tests: 4 failing without live MCP server — mock or skip #9

Description

@dzuluaga

Problem

`uv run pytest` in `backend/` reports 22 passing, 4 failing. All four failures need a live MCP server running at `http://localhost:3001/mcp\`:

  • `tests/test_tools.py::test_place_order_returns_payment_challenge` — `run_tool("place_order", ...)` calls FastMCP client internally
  • `tests/test_tools.py::test_x402_settle_returns_tx_hash` — same path via `place_order`
  • `tests/test_tools.py::test_agent_emits_a2ui_then_end` — `GiftAgent.turn()` fetches MCP schemas at startup
  • `tests/test_app.py::test_agent_uses_beta_client_with_mcp_servers` — see related issue (dead code)

Options (pick per-test)

  1. Mock the FastMCP client: `pytest.fixture` returning a stub `McpClient` that yields canned schemas / tool results. Most flexible.
  2. Mark `@pytest.mark.integration` + skip by default: run only when `MCP_URL` env is set + server reachable. Good for the agent-roundtrip ones.
  3. Start an MCP server in a `pytest.fixture(scope="session")`: launch `mcp/server.py` subprocess, tear down at session end. Most realistic but slowest.

Recommended split

  • Tool-level tests (`place_order`, `x402_settle`) → mock the MCP client
  • Agent-turn test → integration mark + skip unless server up

Caught by

PR #4 rebase validation — run_tool became async in PR #1 (FastMCP integration); the rebased state inherits the dependency without mocks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions