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

16 statements  

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

1import importlib 1abcdefgh

2from types import ModuleType 1abcdefgh

3 

4import pytest 1abcdefgh

5from sqlalchemy import inspect 1abcdefgh

6from sqlalchemy.engine.reflection import Inspector 1abcdefgh

7from sqlmodel import create_engine 1abcdefgh

8 

9 

10@pytest.fixture( 1abcdefgh

11 name="module", 

12 params=[ 

13 pytest.param("tutorial002_py310"), 

14 ], 

15) 

16def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefgh

17 module = importlib.import_module( 1abcdefgh

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

19 ) 

20 module.sqlite_url = "sqlite://" 1abcdefgh

21 module.engine = create_engine(module.sqlite_url) 1abcdefgh

22 return module 1abcdefgh

23 

24 

25def test_create_db_and_table(module: ModuleType): 1abcdefgh

26 module.create_db_and_tables() 1ijklmnop

27 insp: Inspector = inspect(module.engine) 1ijklmnop

28 assert insp.has_table(str(module.Hero.__tablename__)) 1ijklmnop