|
1 | 1 | import os |
2 | 2 | from collections.abc import AsyncIterator, Iterator |
3 | 3 |
|
| 4 | +import httpcore2 as _httpcore2 |
4 | 5 | import pytest |
| 6 | +from blockbuster import BlockBuster |
5 | 7 |
|
6 | 8 | # OpenTelemetry's `set_tracer_provider` is set-once per process, so the suite |
7 | 9 | # uses a single span-capture mechanism: logfire's `capfire` fixture (its |
|
17 | 19 |
|
18 | 20 | import mcp.shared._otel # noqa: E402 |
19 | 21 |
|
| 22 | +# Load httpx2's lazy default transport before BlockBuster starts. |
| 23 | +del _httpcore2 |
| 24 | + |
20 | 25 |
|
21 | 26 | @pytest.fixture(scope="session") |
22 | 27 | def anyio_backend() -> str: |
23 | 28 | return "asyncio" |
24 | 29 |
|
25 | 30 |
|
| 31 | +_BLOCKBUSTER = BlockBuster(["mcp", "mcp_types"]) |
| 32 | +# Coverage reads source files while collecting data. |
| 33 | +_BLOCKBUSTER.functions["os.stat"].can_block_in("coverage/python.py", "get_python_source") |
| 34 | +_BLOCKBUSTER.functions["io.BufferedReader.read"].can_block_in("coverage/python.py", "read_python_source") |
| 35 | +# These public synchronous conversions read the media file by design. |
| 36 | +_BLOCKBUSTER.functions["io.BufferedReader.read"].can_block_in( |
| 37 | + "mcp/server/mcpserver/utilities/types.py", ("to_image_content", "to_audio_content") |
| 38 | +) |
| 39 | + |
| 40 | + |
| 41 | +@pytest.fixture(autouse=True) |
| 42 | +def blockbuster() -> Iterator[BlockBuster]: |
| 43 | + try: |
| 44 | + _BLOCKBUSTER.activate() |
| 45 | + yield _BLOCKBUSTER |
| 46 | + finally: |
| 47 | + _BLOCKBUSTER.deactivate() |
| 48 | + |
| 49 | + |
26 | 50 | @pytest.fixture(scope="module", autouse=True) |
27 | 51 | async def _module_runner_lease(anyio_backend: str) -> AsyncIterator[None]: |
28 | 52 | """Share one event loop across each module's tests instead of one per test. |
|
0 commit comments