Coverage for tests / test_tutorial / test_create_db_and_table / test_tutorial003.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-01-06 21:09 +0000

1import importlib 1abcdefghi

2from types import ModuleType 1abcdefghi

3 

4import pytest 1abcdefghi

5from sqlalchemy import inspect 1abcdefghi

6from sqlalchemy.engine.reflection import Inspector 1abcdefghi

7from sqlmodel import create_engine 1abcdefghi

8 

9from ...conftest import needs_py310 1abcdefghi

10 

11 

12@pytest.fixture( 1abcdefghi

13 name="module", 

14 params=[ 

15 "tutorial003_py39", 

16 pytest.param("tutorial003_py310", marks=needs_py310), 

17 ], 

18) 

19def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghi

20 module = importlib.import_module( 1abcdefghi

21 f"docs_src.tutorial.create_db_and_table.{request.param}" 

22 ) 

23 module.sqlite_url = "sqlite://" 1abcdefghi

24 module.engine = create_engine(module.sqlite_url) 1abcdefghi

25 return module 1abcdefghi

26 

27 

28def test_create_db_and_table(module: ModuleType): 1abcdefghi

29 module.create_db_and_tables() 1jklmnopqr

30 insp: Inspector = inspect(module.engine) 1jklmnopqr

31 assert insp.has_table(str(module.Hero.__tablename__)) 1jklmnopqr