Hi <@ULVA73B9P> on a mac M4 I'm having trouble to ...
# ask-marvin
v
Hi @Marvin on a mac M4 I'm having trouble to launch the prefect_test_harnass, test_server.start() fails with
Timed out while attempting to connect to ephemeral Prefect API server.
m
thought for 223.3 seconds
Thanks for the details — that error means the ephemeral API subprocess didn’t come up quickly enough for the health check. Quick things to try on Apple Silicon (M3/M4): - Increase the ephemeral server startup timeout (Apple Silicon + coverage/plugins can slow startup) - In tests:
Copy code
from prefect.testing.utilities import prefect_test_harness

  def test_something():
      with prefect_test_harness(server_startup_timeout=90):
          ...
- Or via env var when running tests:
Copy code
PREFECT_SERVER_EPHEMERAL_STARTUP_TIMEOUT_SECONDS=90 pytest
- If you’re starting the server directly, pass a longer timeout:
Copy code
from prefect.server.api.server import SubprocessASGIServer

  s = SubprocessASGIServer()
  s.start(timeout=90)
  print(s.api_url)
  s.stop()
- If you’re running tests in parallel (e.g., pytest-xdist), ensure each worker has its own harness instance and avoids sharing a SQLite file. A session-scoped, autouse fixture is the usual pattern:
Copy code
import pytest
  from prefect.testing.utilities import prefect_test_harness

  @pytest.fixture(autouse=True, scope="session")
  def _prefect_test_env():
      with prefect_test_harness(server_startup_timeout=90):
          yield
- Check for port conflicts (the ephemeral server probes ports in the 8000–9000 range):
Copy code
lsof -nP -iTCP -sTCP:LISTEN | grep '8[0-9][0-9][0-9]'
- Ensure Python has SQLite support (the ephemeral server uses SQLite by default):
Copy code
python -c "import sqlite3; print(sqlite3.sqlite_version)"
- Turn up logging to see what’s happening during startup:
Copy code
PREFECT_LOGGING_LEVEL=DEBUG pytest
You can also start a server manually to verify your environment:
Copy code
prefect server start --log-level DEBUG
  # then hit <http://127.0.0.1:4200/api/health>
Why this helps: - On macOS ARM, process spawn + import time (uvicorn/fastapi/sqlalchemy, test coverage, etc.) can push startup past the default 20–30s check, so bumping to 60–90s is often enough. - Parallel test runs can collide on the same SQLite file or saturate the port probe window, causing health checks to time out. If it still times out after increasing the timeout: - Let me know your Prefect version, Python version/arch (arm64 vs x86_64/Rosetta), and whether you’re running tests in parallel. - If you can share the first 50–100 lines of DEBUG logs around server startup, I can pinpoint whether it’s port contention, DB init/migrations taking too long, or something else. References: - Testing workflows guide: Testing workflows (Prefect 3) - Harness API: prefect_test_harness API - Ephemeral server settings: Server ephemeral settings