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
()
| 128 | |
| 129 | @pytest_asyncio.fixture(scope="function") |
| 130 | async 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") |
nothing calls this directly
no test coverage detected
searching dependent graphs…