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

Function db_isolated

conftest.py:130–155  ·  view source on GitHub ↗

Function-scoped fixture with full database recreation per test. Creates a completely fresh database for EACH test. This is the SLOWEST method but provides maximum isolation. Use when: - Testing database creation/dropping - Tests need custom model modules - Tests must h

()

Source from the content-addressed store, hash-verified

128
129@pytest_asyncio.fixture(scope="function")
130async def db_isolated():
131 """
132 Function-scoped fixture with full database recreation per test.
133
134 Creates a completely fresh database for EACH test. This is the SLOWEST
135 method but provides maximum isolation.
136
137 Use when:
138 - Testing database creation/dropping
139 - Tests need custom model modules
140 - Tests must have completely clean state
141
142 Usage:
143 @pytest.mark.asyncio
144 async def test_with_fresh_db(db_isolated):
145 # Completely fresh database
146 ...
147 """
148 db_url = os.getenv("TORTOISE_TEST_DB", "sqlite://:memory:")
149 async with tortoise_test_context(
150 modules=["tests.testmodels"],
151 db_url=db_url,
152 app_label="models",
153 connection_label="models",
154 ) as ctx:
155 yield ctx
156
157
158@pytest_asyncio.fixture(scope="function")

Callers

nothing calls this directly

Calls 1

tortoise_test_contextFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…