MCPcopy
hub / github.com/tortoise/tortoise-orm / two_databases

Function two_databases

tests/test_two_databases.py:19–50  ·  view source on GitHub ↗

Fixture that sets up two separate databases for testing.

()

Source from the content-addressed store, hash-verified

17
18@pytest_asyncio.fixture(scope="function")
19async def two_databases():
20 """Fixture that sets up two separate databases for testing."""
21 db_url = os.getenv("TORTOISE_TEST_DB", "sqlite://:memory:")
22
23 from tortoise.backends.base.config_generator import expand_db_url
24
25 # Expand the URL with uniqueness if it's a template
26 # This ensures "models" and "events" get different DB names if TORTOISE_TEST_DB has {}
27 db1_config = expand_db_url(db_url, testing=True)
28 db2_config = expand_db_url(db_url, testing=True)
29
30 ctx = TortoiseContext()
31 async with ctx:
32 await ctx.init(
33 config={
34 "connections": {
35 "models": db1_config,
36 "events": db2_config,
37 },
38 "apps": {
39 "models": {"models": ["tests.testmodels"], "default_connection": "models"},
40 "events": {"models": ["tests.testmodels"], "default_connection": "events"},
41 },
42 },
43 _create_db=True,
44 )
45 await ctx.generate_schemas()
46
47 db = ctx.connections.get("models")
48 second_db = ctx.connections.get("events")
49
50 yield db, second_db
51
52
53def build_select_sql(db) -> str:

Callers

nothing calls this directly

Calls 5

initMethod · 0.95
generate_schemasMethod · 0.95
expand_db_urlFunction · 0.90
TortoiseContextClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…