mirror of
https://github.com/RunLit/Bambu-Run.git
synced 2026-10-21 15:37:38 +01:00
Also fixes async-test DB isolation: test_mcp_toolkit.py drives real MCP dispatch, which runs tool functions' ORM calls on a sync_to_async worker thread outside pytest-django's per-test atomic transaction, so writes committed there weren't rolled back and leaked into later tests. Sets DJANGO_ALLOW_ASYNC_UNSAFE for the async ORM setup calls and flushes the Printer table after this file's tests via conftest.py.
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""Minimal Django settings for running bambu_run's pytest suite (in-memory SQLite)."""
|
|
import os
|
|
|
|
# test_mcp_toolkit.py drives real MCP dispatch through `mcp.client.Client`,
|
|
# which runs the test body on the asyncio event loop (via pytest-anyio) while
|
|
# still using plain synchronous Django ORM calls (Printer.objects.create(),
|
|
# and the ORM calls inside the tool functions themselves). Django's asyncio
|
|
# safety net treats any sync ORM call made while an event loop is running as
|
|
# unsafe by default. It's genuinely safe here: sqlite is in-memory, tests run
|
|
# single-threaded, and there's no concurrent request interleaving to corrupt
|
|
# a shared connection. Set at settings-import time (before any test body
|
|
# runs) rather than per-test, since Django reads this env var at call time.
|
|
os.environ.setdefault("DJANGO_ALLOW_ASYNC_UNSAFE", "1")
|
|
|
|
SECRET_KEY = "test-secret-key"
|
|
|
|
INSTALLED_APPS = [
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"bambu_run",
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
]
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"APP_DIRS": True,
|
|
"OPTIONS": {
|
|
"context_processors": [
|
|
"django.template.context_processors.request",
|
|
"django.contrib.auth.context_processors.auth",
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": ":memory:",
|
|
}
|
|
}
|
|
|
|
USE_TZ = True
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
ROOT_URLCONF = "tests.urls"
|