Coverage for tests/test_advanced/test_datetime/test_tutorial003.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-16 00:02 +0000

1import importlib 1abcdefghijklm

2from datetime import UTC, datetime 1abcdefghijklm

3from types import ModuleType 1abcdefghijklm

4 

5import pytest 1abcdefghijklm

6from sqlmodel import SQLModel 1abcdefghijklm

7 

8from ...conftest import PrintMock 1abcdefghijklm

9 

10 

11@pytest.fixture( 1abcdefghijklm

12 name="mod", 

13 params=[ 

14 pytest.param("tutorial003"), 

15 ], 

16) 

17def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghijklm

18 return importlib.import_module(f"docs_src.advanced.datetime.{request.param}") 1abcdefghijklm

19 

20 

21def test_tutorial(print_mock: PrintMock, mod: ModuleType) -> None: 1abcdefghijklm

22 mod.main() 1nopqrstuvwxyz

23 assert print_mock.calls == [ 1nopqrstuvwxyz

24 ["Event:", {"id": None, "created_at": datetime(2026, 1, 1, 12)}] 

25 ] 

26 

27 aware = datetime(2026, 1, 1, 12, tzinfo=UTC) 1nopqrstuvwxyz

28 assert mod.Event.model_validate({"created_at": aware}).created_at == aware 1nopqrstuvwxyz

29 

30 table = SQLModel.metadata.tables["event"] 1nopqrstuvwxyz

31 assert table.c.created_at.type.timezone is False 1nopqrstuvwxyz