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

Function db_truncate

conftest.py:159–176  ·  view source on GitHub ↗

Function-scoped fixture with table truncation cleanup. After each test, all tables are truncated (DELETE FROM). Faster than db_isolated but slower than db (transaction rollback). Use when testing transaction behavior (can't use rollback for cleanup). Usage: @pytest.ma

(db_module)

Source from the content-addressed store, hash-verified

157
158@pytest_asyncio.fixture(scope="function")
159async def db_truncate(db_module):
160 """
161 Function-scoped fixture with table truncation cleanup.
162
163 After each test, all tables are truncated (DELETE FROM).
164 Faster than db_isolated but slower than db (transaction rollback).
165
166 Use when testing transaction behavior (can't use rollback for cleanup).
167
168 Usage:
169 @pytest.mark.asyncio
170 async def test_with_transactions(db_truncate):
171 async with in_transaction():
172 await Model.create(name="test")
173 # Table truncated after test
174 """
175 yield db_module
176 await _truncate_all_tables(db_module)
177
178
179# ============================================================================

Callers

nothing calls this directly

Calls 1

_truncate_all_tablesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…