]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
authorpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Thu, 19 Jun 2025 21:21:30 +0000 (21:21 +0000)
committerpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Thu, 19 Jun 2025 21:21:31 +0000 (21:21 +0000)
20 files changed:
tests/test_advanced/test_decimal/test_tutorial001.py
tests/test_tutorial/test_connect/test_delete/test_tutorial001.py
tests/test_tutorial/test_connect/test_insert/test_tutorial001.py
tests/test_tutorial/test_connect/test_select/test_tutorial003.py
tests/test_tutorial/test_connect/test_select/test_tutorial004.py
tests/test_tutorial/test_connect/test_select/test_tutorial005.py
tests/test_tutorial/test_connect/test_update/test_tutorial001.py
tests/test_tutorial/test_create_db_and_table/test_tutorial002.py
tests/test_tutorial/test_create_db_and_table/test_tutorial003.py
tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests_main.py
tests/test_tutorial/test_fastapi/test_delete/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_limit_and_offset/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py
tests/test_tutorial/test_fastapi/test_read_one/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_relationships/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_response_model/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_session_with_dependency/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_simple_hero_api/test_tutorial001.py
tests/test_tutorial/test_fastapi/test_teams/test_tutorial001.py

index 4166e22ba51d48712d34f5aba5a5cae5ea629262..2be19e6ce3b150810f81c17b1d6382bfec4796fa 100644 (file)
@@ -1,12 +1,11 @@
 import importlib
-import types # Add import for types
+import types  # Add import for types
 from decimal import Decimal
-from unittest.mock import MagicMock # Keep MagicMock for type hint, though not strictly necessary for runtime
 
 import pytest
 from sqlmodel import create_engine
 
-from ...conftest import needs_py310, PrintMock # Import PrintMock for type hint
+from ...conftest import PrintMock, needs_py310  # Import PrintMock for type hint
 
 expected_calls = [
     [
@@ -45,8 +44,10 @@ def get_module(request: pytest.FixtureRequest):
     return importlib.import_module(f"docs_src.advanced.decimal.{module_name}")
 
 
-def test_tutorial(print_mock: PrintMock, module: types.ModuleType): # Use PrintMock for type hint and types.ModuleType
+def test_tutorial(
+    print_mock: PrintMock, module: types.ModuleType
+):  # Use PrintMock for type hint and types.ModuleType
     module.sqlite_url = "sqlite://"
     module.engine = create_engine(module.sqlite_url)
     module.main()
-    assert print_mock.calls == expected_calls # Use .calls instead of .mock_calls
+    assert print_mock.calls == expected_calls  # Use .calls instead of .mock_calls
index 04b68397bddc5e01a59eb9d9c6a45cd96ad4d7b1..7e1a1687e88bb3912cfb00abb9de80aa7a7314b5 100644 (file)
@@ -69,9 +69,7 @@ expected_calls = [
 )
 def get_module(request: pytest.FixtureRequest) -> ModuleType:
     module_name = request.param
-    mod = importlib.import_module(
-        f"docs_src.tutorial.connect.delete.{module_name}"
-    )
+    mod = importlib.import_module(f"docs_src.tutorial.connect.delete.{module_name}")
     mod.sqlite_url = "sqlite://"
     mod.engine = create_engine(mod.sqlite_url)
     return mod
index 5a29f5d89975844a210dd156e2fd5e691ecff933..2884de3e1a83c2944fc039ede9a63b189899a6a0 100644 (file)
@@ -49,9 +49,7 @@ expected_calls = [
 )
 def get_module(request: pytest.FixtureRequest) -> ModuleType:
     module_name = request.param
-    mod = importlib.import_module(
-        f"docs_src.tutorial.connect.insert.{module_name}"
-    )
+    mod = importlib.import_module(f"docs_src.tutorial.connect.insert.{module_name}")
     mod.sqlite_url = "sqlite://"
     mod.engine = create_engine(mod.sqlite_url)
     return mod
index 2b6d4235bbb6de52ae92218ffa6ab3557368d39a..bc5a9c383ec41e7ea81cd2c24c3d4d2109b896be 100644 (file)
@@ -85,9 +85,7 @@ expected_calls = [
 )
 def get_module(request: pytest.FixtureRequest) -> ModuleType:
     module_name = request.param
-    mod = importlib.import_module(
-        f"docs_src.tutorial.connect.select.{module_name}"
-    )
+    mod = importlib.import_module(f"docs_src.tutorial.connect.select.{module_name}")
     mod.sqlite_url = "sqlite://"
     mod.engine = create_engine(mod.sqlite_url)
     return mod
index ecf00c9644542e7f443dc49a62d7bca663670a7e..10b1e864c8c40a68b8d74607d7cb8f713fc6fd5d 100644 (file)
@@ -59,9 +59,7 @@ expected_calls = [
 )
 def get_module(request: pytest.FixtureRequest) -> ModuleType:
     module_name = request.param
-    mod = importlib.import_module(
-        f"docs_src.tutorial.connect.select.{module_name}"
-    )
+    mod = importlib.import_module(f"docs_src.tutorial.connect.select.{module_name}")
     mod.sqlite_url = "sqlite://"
     mod.engine = create_engine(mod.sqlite_url)
     return mod
index 0c64821a93a622b5765705fc42b6e9188ff2198c..fec4122e65923fca7023aa9045857f422fefcf8a 100644 (file)
@@ -61,9 +61,7 @@ expected_calls = [
 )
 def get_module(request: pytest.FixtureRequest) -> ModuleType:
     module_name = request.param
-    mod = importlib.import_module(
-        f"docs_src.tutorial.connect.select.{module_name}"
-    )
+    mod = importlib.import_module(f"docs_src.tutorial.connect.select.{module_name}")
     mod.sqlite_url = "sqlite://"
     mod.engine = create_engine(mod.sqlite_url)
     return mod
index e14e30e945140c8f7ffd77dece499451636fdc17..57032565f5fb9cdb161db86f11412cace04d61fe 100644 (file)
@@ -1,6 +1,6 @@
 import importlib
 from types import ModuleType
-from typing import Any # For clear_sqlmodel type hint
+from typing import Any  # For clear_sqlmodel type hint
 
 import pytest
 from sqlmodel import create_engine
@@ -60,14 +60,14 @@ expected_calls = [
 )
 def get_module(request: pytest.FixtureRequest) -> ModuleType:
     module_name = request.param
-    mod = importlib.import_module(
-        f"docs_src.tutorial.connect.update.{module_name}"
-    )
+    mod = importlib.import_module(f"docs_src.tutorial.connect.update.{module_name}")
     mod.sqlite_url = "sqlite://"
     mod.engine = create_engine(mod.sqlite_url)
     return mod
 
 
-def test_tutorial(clear_sqlmodel: Any, print_mock: PrintMock, module: ModuleType) -> None:
+def test_tutorial(
+    clear_sqlmodel: Any, print_mock: PrintMock, module: ModuleType
+) -> None:
     module.main()
     assert print_mock.calls == expected_calls
index c5e21c252f2dc6ce7b97a78b00dbc5528cc397f8..c3330488c30628ed8005692c0256d29bcd0d051e 100644 (file)
@@ -1,6 +1,6 @@
 import importlib
 from types import ModuleType
-from typing import Any # For clear_sqlmodel type hint
+from typing import Any  # For clear_sqlmodel type hint
 
 import pytest
 from sqlalchemy import inspect
index e67673bd5e046a18bb55b903f209f27ea457f321..5aa3b8ace58d5f257900bea834db8b14f4b60a13 100644 (file)
@@ -1,6 +1,6 @@
 import importlib
 from types import ModuleType
-from typing import Any # For clear_sqlmodel type hint
+from typing import Any  # For clear_sqlmodel type hint
 
 import pytest
 from sqlalchemy import inspect
index 7313ef958bb4a32ca225d8ff1cd2cabf278a2f7e..535b33013ea678700c21150d2cb84bc8722680fb 100644 (file)
@@ -1,15 +1,16 @@
 import importlib
-import sys # Add sys import
+import sys  # Add sys import
 from types import ModuleType
 from typing import Any, Generator
 
 import pytest
 from fastapi.testclient import TestClient
-from sqlmodel import Session, SQLModel, create_engine # Keep this for session_fixture
-from sqlmodel.pool import StaticPool # Keep this for session_fixture
+from sqlmodel import Session, SQLModel, create_engine  # Keep this for session_fixture
+from sqlmodel.pool import StaticPool  # Keep this for session_fixture
 
 from ....conftest import needs_py39, needs_py310
 
+
 # This will be our parametrized fixture providing the versioned 'main' module
 @pytest.fixture(
     name="module",
@@ -20,7 +21,9 @@ from ....conftest import needs_py39, needs_py310
         pytest.param("tutorial001_py310", marks=needs_py310),
     ],
 )
-def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleType: # clear_sqlmodel is autouse
+def get_module(
+    request: pytest.FixtureRequest, clear_sqlmodel: Any
+) -> ModuleType:  # clear_sqlmodel is autouse
     module_name = f"docs_src.tutorial.fastapi.app_testing.{request.param}.main"
 
     # Forcing reload to try to get a fresh state for models
@@ -30,6 +33,7 @@ def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleTyp
         module = importlib.import_module(module_name)
     return module
 
+
 @pytest.fixture(name="session", scope="function")
 def session_fixture(module: ModuleType) -> Generator[Session, None, None]:
     # Store original engine-related attributes from the module
@@ -39,13 +43,13 @@ def session_fixture(module: ModuleType) -> Generator[Session, None, None]:
 
     # Force module to use a fresh in-memory SQLite DB for this test run
     module.sqlite_url = "sqlite://"
-    module.connect_args = {"check_same_thread": False} # Crucial for FastAPI + SQLite
+    module.connect_args = {"check_same_thread": False}  # Crucial for FastAPI + SQLite
 
     # Re-create the engine in the module to use these new settings
     test_engine = create_engine(
         module.sqlite_url,
         connect_args=module.connect_args,
-        poolclass=StaticPool  # Recommended for tests
+        poolclass=StaticPool,  # Recommended for tests
     )
     module.engine = test_engine
 
@@ -55,7 +59,9 @@ def session_fixture(module: ModuleType) -> Generator[Session, None, None]:
         # Fallback if the function isn't named create_db_and_tables
         SQLModel.metadata.create_all(module.engine)
 
-    with Session(module.engine) as session: # Use the module's (now test-configured) engine
+    with Session(
+        module.engine
+    ) as session:  # Use the module's (now test-configured) engine
         yield session
 
     # Teardown: drop tables from the module's engine
@@ -68,14 +74,16 @@ def session_fixture(module: ModuleType) -> Generator[Session, None, None]:
         module.connect_args = original_connect_args
     if original_engine is not None:
         module.engine = original_engine
-    else: # If engine didn't exist, remove the one we created
+    else:  # If engine didn't exist, remove the one we created
         if hasattr(module, "engine"):
             del module.engine
 
 
 @pytest.fixture(name="client", scope="function")
-def client_fixture(session: Session, module: ModuleType) -> Generator[TestClient, None, None]:
-    def get_session_override() -> Generator[Session, None, None]: # Must be a generator
+def client_fixture(
+    session: Session, module: ModuleType
+) -> Generator[TestClient, None, None]:
+    def get_session_override() -> Generator[Session, None, None]:  # Must be a generator
         yield session
 
     module.app.dependency_overrides[module.get_session] = get_session_override
@@ -140,7 +148,7 @@ def test_read_heroes(session: Session, client: TestClient, module: ModuleType):
 
 
 def test_read_hero(session: Session, client: TestClient, module: ModuleType):
-    hero_1 = module.Hero(name="Deadpond", secret_name="Dive Wilson") # Use module.Hero
+    hero_1 = module.Hero(name="Deadpond", secret_name="Dive Wilson")  # Use module.Hero
     session.add(hero_1)
     session.commit()
 
@@ -155,7 +163,7 @@ def test_read_hero(session: Session, client: TestClient, module: ModuleType):
 
 
 def test_update_hero(session: Session, client: TestClient, module: ModuleType):
-    hero_1 = module.Hero(name="Deadpond", secret_name="Dive Wilson") # Use module.Hero
+    hero_1 = module.Hero(name="Deadpond", secret_name="Dive Wilson")  # Use module.Hero
     session.add(hero_1)
     session.commit()
 
@@ -170,13 +178,13 @@ def test_update_hero(session: Session, client: TestClient, module: ModuleType):
 
 
 def test_delete_hero(session: Session, client: TestClient, module: ModuleType):
-    hero_1 = module.Hero(name="Deadpond", secret_name="Dive Wilson") # Use module.Hero
+    hero_1 = module.Hero(name="Deadpond", secret_name="Dive Wilson")  # Use module.Hero
     session.add(hero_1)
     session.commit()
 
     response = client.delete(f"/heroes/{hero_1.id}")
 
-    hero_in_db = session.get(module.Hero, hero_1.id) # Use module.Hero
+    hero_in_db = session.get(module.Hero, hero_1.id)  # Use module.Hero
 
     assert response.status_code == 200
     assert hero_in_db is None
index 2d37d405c71cb1fcf1644f692dafb32199589879..08016f86f5531a6e11893cf0ef40485d5799ab97 100644 (file)
@@ -1,12 +1,12 @@
 import importlib
 import sys
 from types import ModuleType
-from typing import Any # For clear_sqlmodel type hint
+from typing import Any  # For clear_sqlmodel type hint
 
 import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
-from sqlmodel import SQLModel, create_engine # Import SQLModel for metadata operations
+from sqlmodel import SQLModel, create_engine  # Import SQLModel for metadata operations
 from sqlmodel.pool import StaticPool
 
 from ....conftest import needs_py39, needs_py310
@@ -22,7 +22,7 @@ from ....conftest import needs_py39, needs_py310
     ],
 )
 def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleType:
-    module_name = f"docs_src.tutorial.fastapi.delete.{request.param}" # No .main here
+    module_name = f"docs_src.tutorial.fastapi.delete.{request.param}"  # No .main here
     if module_name in sys.modules:
         module = importlib.reload(sys.modules[module_name])
     else:
@@ -34,19 +34,23 @@ def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleTyp
     module.sqlite_url = "sqlite://"
     module.engine = create_engine(
         module.sqlite_url,
-        connect_args={"check_same_thread": False}, # connect_args from original main.py
-        poolclass=StaticPool
+        connect_args={"check_same_thread": False},  # connect_args from original main.py
+        poolclass=StaticPool,
     )
     # Assuming the module has a create_db_and_tables or similar, or uses SQLModel.metadata directly
     if hasattr(module, "create_db_and_tables"):
         module.create_db_and_tables()
     else:
-        SQLModel.metadata.create_all(module.engine) # Fallback, ensure tables are created
+        SQLModel.metadata.create_all(
+            module.engine
+        )  # Fallback, ensure tables are created
 
     return module
 
 
-def test_tutorial(clear_sqlmodel: Any, module: ModuleType): # clear_sqlmodel is autouse but explicit for safety
+def test_tutorial(
+    clear_sqlmodel: Any, module: ModuleType
+):  # clear_sqlmodel is autouse but explicit for safety
     # The engine and tables are now set up by the 'module' fixture
     # The app's dependency overrides for get_session will use module.engine
 
@@ -56,7 +60,7 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType): # clear_sqlmodel is
         hero2_data = {
             "name": "Spider-Boy",
             "secret_name": "Pedro Parqueador",
-            "id": 9000, # Note: ID is part of creation data here
+            "id": 9000,  # Note: ID is part of creation data here
         }
         hero3_data = {
             "name": "Rusty-Man",
@@ -65,13 +69,15 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType): # clear_sqlmodel is
         }
         response = client.post("/heroes/", json=hero1_data)
         assert response.status_code == 200, response.text
-        hero1 = response.json() # Get actual ID of hero1
+        hero1 = response.json()  # Get actual ID of hero1
         hero1_id = hero1["id"]
 
         response = client.post("/heroes/", json=hero2_data)
         assert response.status_code == 200, response.text
         hero2 = response.json()
-        hero2_id = hero2["id"] # This will be the ID assigned by DB, not 9000 if 9000 is not allowed on POST
+        hero2_id = hero2[
+            "id"
+        ]  # This will be the ID assigned by DB, not 9000 if 9000 is not allowed on POST
 
         response = client.post("/heroes/", json=hero3_data)
         assert response.status_code == 200, response.text
@@ -86,8 +92,8 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType): # clear_sqlmodel is
         # For robustness, let's check for a non-existent ID based on actual data.
         # If hero2_id is 1, check for 9000. If it's 9000, check for 1 (assuming hero1_id is 1).
         non_existent_id_check = 9000
-        if hero2_id == non_existent_id_check: # if DB somehow used 9000
-            non_existent_id_check = hero1_id + hero2_id + 100 # just some other ID
+        if hero2_id == non_existent_id_check:  # if DB somehow used 9000
+            non_existent_id_check = hero1_id + hero2_id + 100  # just some other ID
 
         response = client.get(f"/heroes/{non_existent_id_check}")
         assert response.status_code == 404, response.text
@@ -102,7 +108,9 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType): # clear_sqlmodel is
         )
         assert response.status_code == 200, response.text
 
-        response = client.patch(f"/heroes/{non_existent_id_check}", json={"name": "Dragon Cube X"})
+        response = client.patch(
+            f"/heroes/{non_existent_id_check}", json={"name": "Dragon Cube X"}
+        )
         assert response.status_code == 404, response.text
 
         response = client.delete(f"/heroes/{hero2_id}")
@@ -111,7 +119,7 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType): # clear_sqlmodel is
         response = client.get("/heroes/")
         assert response.status_code == 200, response.text
         data = response.json()
-        assert len(data) == 2 # After deleting one hero
+        assert len(data) == 2  # After deleting one hero
 
         response = client.delete(f"/heroes/{non_existent_id_check}")
         assert response.status_code == 404, response.text
index 2ce49c1e03621fc27827c20bbf2c2e1ef0578b95..8909e98fffab4e37d57bb593db49faa729014dfc 100644 (file)
@@ -1,12 +1,12 @@
 import importlib
 import sys
 from types import ModuleType
-from typing import Any # For clear_sqlmodel type hint
+from typing import Any  # For clear_sqlmodel type hint
 
 import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
-from sqlmodel import SQLModel, create_engine # Import SQLModel for metadata operations
+from sqlmodel import SQLModel, create_engine  # Import SQLModel for metadata operations
 from sqlmodel.pool import StaticPool
 
 from ....conftest import needs_py39, needs_py310
@@ -22,7 +22,9 @@ from ....conftest import needs_py39, needs_py310
     ],
 )
 def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleType:
-    module_name = f"docs_src.tutorial.fastapi.limit_and_offset.{request.param}" # No .main
+    module_name = (
+        f"docs_src.tutorial.fastapi.limit_and_offset.{request.param}"  # No .main
+    )
     if module_name in sys.modules:
         module = importlib.reload(sys.modules[module_name])
     else:
@@ -31,8 +33,10 @@ def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleTyp
     module.sqlite_url = "sqlite://"
     module.engine = create_engine(
         module.sqlite_url,
-        connect_args={"check_same_thread": False}, # Assuming connect_args was in original mod or default
-        poolclass=StaticPool
+        connect_args={
+            "check_same_thread": False
+        },  # Assuming connect_args was in original mod or default
+        poolclass=StaticPool,
     )
     if hasattr(module, "create_db_and_tables"):
         module.create_db_and_tables()
@@ -66,7 +70,7 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         response = client.post("/heroes/", json=hero2_data)
         assert response.status_code == 200, response.text
         hero2 = response.json()
-        hero2_id = hero2["id"] # Use the actual ID from response
+        hero2_id = hero2["id"]  # Use the actual ID from response
 
         # Create hero 3
         response = client.post("/heroes/", json=hero3_data)
@@ -92,7 +96,9 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         assert response.status_code == 200, response.text
         data_limit2 = response.json()
         assert len(data_limit2) == 2
-        assert data_limit2[0]["name"] == hero1["name"] # Compare with actual created hero data
+        assert (
+            data_limit2[0]["name"] == hero1["name"]
+        )  # Compare with actual created hero data
         assert data_limit2[1]["name"] == hero2["name"]
 
         response = client.get("/heroes/", params={"offset": 1})
index b0c0c6cec6b077ed23411215a4884320d5868de1..cd36fbe9f3949fabea88b21b2d5e9172942545f4 100644 (file)
@@ -1,14 +1,14 @@
 import importlib
 import sys
 from types import ModuleType
-from typing import Any # For clear_sqlmodel type hint
+from typing import Any  # For clear_sqlmodel type hint
 
 import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
 from sqlalchemy import inspect
 from sqlalchemy.engine.reflection import Inspector
-from sqlmodel import SQLModel, create_engine # Import SQLModel
+from sqlmodel import SQLModel, create_engine  # Import SQLModel
 from sqlmodel.pool import StaticPool
 
 from ....conftest import needs_py39, needs_py310
@@ -24,7 +24,9 @@ from ....conftest import needs_py39, needs_py310
     ],
 )
 def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleType:
-    module_name = f"docs_src.tutorial.fastapi.multiple_models.{request.param}" # No .main
+    module_name = (
+        f"docs_src.tutorial.fastapi.multiple_models.{request.param}"  # No .main
+    )
     if module_name in sys.modules:
         module = importlib.reload(sys.modules[module_name])
     else:
@@ -34,13 +36,11 @@ def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleTyp
     # Ensure connect_args is available in module, default if not.
     # Some tutorial files might not define it if they don't use on_event("startup") for engine creation.
     connect_args = getattr(module, "connect_args", {"check_same_thread": False})
-    if "check_same_thread" not in connect_args: # Ensure this specific arg for SQLite
+    if "check_same_thread" not in connect_args:  # Ensure this specific arg for SQLite
         connect_args["check_same_thread"] = False
 
     module.engine = create_engine(
-        module.sqlite_url,
-        connect_args=connect_args,
-        poolclass=StaticPool
+        module.sqlite_url, connect_args=connect_args, poolclass=StaticPool
     )
     if hasattr(module, "create_db_and_tables"):
         module.create_db_and_tables()
@@ -66,7 +66,7 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         assert data["secret_name"] == hero1_data["secret_name"]
         assert data["id"] is not None
         assert data["age"] is None
-        hero1_id = data["id"] # Store actual ID
+        hero1_id = data["id"]  # Store actual ID
 
         response = client.post("/heroes/", json=hero2_data)
         data = response.json()
@@ -78,8 +78,7 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         # This is true if ID is auto-generated and not 9000.
         assert data["id"] is not None
         assert data["age"] is None
-        hero2_id = data["id"] # Store actual ID
-
+        hero2_id = data["id"]  # Store actual ID
 
         response = client.get("/heroes/")
         data = response.json()
@@ -95,7 +94,6 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         assert data[1]["name"] == hero2_data["name"]
         assert data[1]["secret_name"] == hero2_data["secret_name"]
 
-
         response = client.get("/openapi.json")
         assert response.status_code == 200, response.text
         # OpenAPI schema check - kept as is from original test
@@ -237,8 +235,8 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         }
 
     # Test inherited indexes
-    insp: Inspector = inspect(module.engine) # Use module.engine
-    indexes = insp.get_indexes(str(module.Hero.__tablename__)) # Use module.Hero
+    insp: Inspector = inspect(module.engine)  # Use module.engine
+    indexes = insp.get_indexes(str(module.Hero.__tablename__))  # Use module.Hero
     expected_indexes = [
         {
             "name": "ix_hero_name",
@@ -255,10 +253,16 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
     ]
     # Convert list of dicts to list of tuples of sorted items for order-agnostic comparison
     indexes_for_comparison = [tuple(sorted(d.items())) for d in indexes]
-    expected_indexes_for_comparison = [tuple(sorted(d.items())) for d in expected_indexes]
+    expected_indexes_for_comparison = [
+        tuple(sorted(d.items())) for d in expected_indexes
+    ]
 
     for index_data_tuple in expected_indexes_for_comparison:
-        assert index_data_tuple in indexes_for_comparison, f"Expected index {index_data_tuple} not found in DB indexes {indexes_for_comparison}"
+        assert index_data_tuple in indexes_for_comparison, (
+            f"Expected index {index_data_tuple} not found in DB indexes {indexes_for_comparison}"
+        )
         indexes_for_comparison.remove(index_data_tuple)
 
-    assert len(indexes_for_comparison) == 0, f"Unexpected extra indexes found in DB: {indexes_for_comparison}"
+    assert len(indexes_for_comparison) == 0, (
+        f"Unexpected extra indexes found in DB: {indexes_for_comparison}"
+    )
index bff3992764585de683b0a356862214d59b1f481d..92cf5cbf6dd2c6b372225e31a3fa7801ebb6b4cd 100644 (file)
@@ -1,14 +1,14 @@
 import importlib
 import sys
 from types import ModuleType
-from typing import Any # For clear_sqlmodel type hint
+from typing import Any  # For clear_sqlmodel type hint
 
 import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
 from sqlalchemy import inspect
 from sqlalchemy.engine.reflection import Inspector
-from sqlmodel import SQLModel, create_engine # Import SQLModel
+from sqlmodel import SQLModel, create_engine  # Import SQLModel
 from sqlmodel.pool import StaticPool
 
 from ....conftest import needs_py39, needs_py310
@@ -18,9 +18,13 @@ from ....conftest import needs_py39, needs_py310
     name="module",
     scope="function",
     params=[
-        "tutorial002", # Changed to tutorial002
-        pytest.param("tutorial002_py39", marks=needs_py39), # Changed to tutorial002_py39
-        pytest.param("tutorial002_py310", marks=needs_py310), # Changed to tutorial002_py310
+        "tutorial002",  # Changed to tutorial002
+        pytest.param(
+            "tutorial002_py39", marks=needs_py39
+        ),  # Changed to tutorial002_py39
+        pytest.param(
+            "tutorial002_py310", marks=needs_py310
+        ),  # Changed to tutorial002_py310
     ],
 )
 def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleType:
@@ -36,9 +40,7 @@ def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleTyp
         connect_args["check_same_thread"] = False
 
     module.engine = create_engine(
-        module.sqlite_url,
-        connect_args=connect_args,
-        poolclass=StaticPool
+        module.sqlite_url, connect_args=connect_args, poolclass=StaticPool
     )
     if hasattr(module, "create_db_and_tables"):
         module.create_db_and_tables()
@@ -75,7 +77,6 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         assert data["age"] is None
         hero2_id = data["id"]
 
-
         response = client.get("/heroes/")
         data = response.json()
 
@@ -88,7 +89,6 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         assert data[1]["name"] == hero2_data["name"]
         assert data[1]["secret_name"] == hero2_data["secret_name"]
 
-
         response = client.get("/openapi.json")
         assert response.status_code == 200, response.text
         assert response.json() == {
@@ -233,7 +233,7 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
     indexes = insp.get_indexes(str(module.Hero.__tablename__))
     expected_indexes = [
         {
-            "name": "ix_hero_age", # For tutorial002, order of expected indexes is different
+            "name": "ix_hero_age",  # For tutorial002, order of expected indexes is different
             "dialect_options": {},
             "column_names": ["age"],
             "unique": 0,
@@ -246,10 +246,16 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         },
     ]
     indexes_for_comparison = [tuple(sorted(d.items())) for d in indexes]
-    expected_indexes_for_comparison = [tuple(sorted(d.items())) for d in expected_indexes]
+    expected_indexes_for_comparison = [
+        tuple(sorted(d.items())) for d in expected_indexes
+    ]
 
     for index_data_tuple in expected_indexes_for_comparison:
-        assert index_data_tuple in indexes_for_comparison, f"Expected index {index_data_tuple} not found in DB indexes {indexes_for_comparison}"
+        assert index_data_tuple in indexes_for_comparison, (
+            f"Expected index {index_data_tuple} not found in DB indexes {indexes_for_comparison}"
+        )
         indexes_for_comparison.remove(index_data_tuple)
 
-    assert len(indexes_for_comparison) == 0, f"Unexpected extra indexes found in DB: {indexes_for_comparison}"
+    assert len(indexes_for_comparison) == 0, (
+        f"Unexpected extra indexes found in DB: {indexes_for_comparison}"
+    )
index 0d2b1ec91580cce227ec9941e97c39fc13767543..51fdc80b95f85b81de58958f85f93c6ddc31bfb4 100644 (file)
@@ -22,7 +22,7 @@ from ....conftest import needs_py39, needs_py310
     ],
 )
 def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleType:
-    module_name = f"docs_src.tutorial.fastapi.read_one.{request.param}" # No .main
+    module_name = f"docs_src.tutorial.fastapi.read_one.{request.param}"  # No .main
     if module_name in sys.modules:
         module = importlib.reload(sys.modules[module_name])
     else:
@@ -34,9 +34,7 @@ def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any) -> ModuleTyp
         connect_args["check_same_thread"] = False
 
     module.engine = create_engine(
-        module.sqlite_url,
-        connect_args=connect_args,
-        poolclass=StaticPool
+        module.sqlite_url, connect_args=connect_args, poolclass=StaticPool
     )
     if hasattr(module, "create_db_and_tables"):
         module.create_db_and_tables()
@@ -56,18 +54,18 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         }
         response = client.post("/heroes/", json=hero1_data)
         assert response.status_code == 200, response.text
-        hero1 = response.json() # Store created hero1 data
+        hero1 = response.json()  # Store created hero1 data
 
         response = client.post("/heroes/", json=hero2_data)
         assert response.status_code == 200, response.text
-        hero2 = response.json() # Store created hero2 data
+        hero2 = response.json()  # Store created hero2 data
 
         response_get_all = client.get("/heroes/")
         assert response_get_all.status_code == 200, response_get_all.text
         data_all = response_get_all.json()
         assert len(data_all) == 2
 
-        hero_id_to_get = hero2["id"] # Use actual ID from created hero2
+        hero_id_to_get = hero2["id"]  # Use actual ID from created hero2
         response_get_one = client.get(f"/heroes/{hero_id_to_get}")
         assert response_get_one.status_code == 200, response_get_one.text
         data_one = response_get_one.json()
@@ -77,9 +75,11 @@ def test_tutorial(clear_sqlmodel: Any, module: ModuleType):
         assert data_one["id"] == hero2["id"]
 
         # Check for a non-existent ID
-        non_existent_id = hero1["id"] + hero2["id"] + 100 # A likely non-existent ID
+        non_existent_id = hero1["id"] + hero2["id"] + 100  # A likely non-existent ID
         response_get_non_existent = client.get(f"/heroes/{non_existent_id}")
-        assert response_get_non_existent.status_code == 404, response_get_non_existent.text
+        assert response_get_non_existent.status_code == 404, (
+            response_get_non_existent.text
+        )
 
         response_openapi = client.get("/openapi.json")
         assert response_openapi.status_code == 200, response_openapi.text
index bcb9cb13dc9a692709bdb1020d1c094b71140c77..bc1379d7110cc1d90a53727d99b798feadd9bc09 100644 (file)
@@ -4,9 +4,8 @@ import types
 from typing import Any
 
 import pytest
-from dirty_equals import IsDict
 from fastapi.testclient import TestClient
-from sqlmodel import create_engine, SQLModel
+from sqlmodel import SQLModel, create_engine
 from sqlmodel.pool import StaticPool
 
 from ....conftest import needs_py39, needs_py310
@@ -89,7 +88,7 @@ def test_tutorial(module: types.ModuleType):
         hero2_data = {
             "name": "Spider-Boy",
             "secret_name": "Pedro Parqueador",
-            "id": 9000, # This ID might be problematic if the DB auto-increments differently or if this ID is expected to be user-settable and unique
+            "id": 9000,  # This ID might be problematic if the DB auto-increments differently or if this ID is expected to be user-settable and unique
         }
         hero3_data = {
             "name": "Rusty-Man",
@@ -107,8 +106,10 @@ def test_tutorial(module: types.ModuleType):
         hero2_id = hero2["id"]
         response = client.post("/heroes/", json=hero3_data)
         assert response.status_code == 200, response.text
-        response = client.get("/heroes/9000") # This might fail if hero2_id is not 9000
-        assert response.status_code == 404, response.text # Original test expects 404, this implies ID 9000 is not found after creation. This needs to align with how IDs are handled.
+        response = client.get("/heroes/9000")  # This might fail if hero2_id is not 9000
+        assert response.status_code == 404, (
+            response.text
+        )  # Original test expects 404, this implies ID 9000 is not found after creation. This needs to align with how IDs are handled.
 
         response = client.get("/heroes/")
         assert response.status_code == 200, response.text
@@ -120,18 +121,25 @@ def test_tutorial(module: types.ModuleType):
         data = response.json()
         assert data["name"] == hero1_data["name"]
         # Ensure team is loaded and correct
-        if "team" in data and data["team"] is not None: # Team might not be present if not correctly loaded by the endpoint
+        if (
+            "team" in data and data["team"] is not None
+        ):  # Team might not be present if not correctly loaded by the endpoint
             assert data["team"]["name"] == team_z_force["name"]
-        elif short_module_name != "tutorial001_py310": # tutorial001_py310.py doesn't include team in HeroPublic
-             # If team is expected, this is a failure. For tutorial001 and tutorial001_py39, team should be present.
-            assert "team" in data and data["team"] is not None, "Team data missing in hero response"
-
+        elif (
+            short_module_name != "tutorial001_py310"
+        ):  # tutorial001_py310.py doesn't include team in HeroPublic
+            # If team is expected, this is a failure. For tutorial001 and tutorial001_py39, team should be present.
+            assert "team" in data and data["team"] is not None, (
+                "Team data missing in hero response"
+            )
 
         response = client.patch(
             f"/heroes/{hero2_id}", json={"secret_name": "Spider-Youngster"}
         )
         assert response.status_code == 200, response.text
-        response = client.patch("/heroes/9001", json={"name": "Dragon Cube X"}) # Test patching non-existent hero
+        response = client.patch(
+            "/heroes/9001", json={"name": "Dragon Cube X"}
+        )  # Test patching non-existent hero
         assert response.status_code == 404, response.text
 
         response = client.delete(f"/heroes/{hero2_id}")
@@ -140,24 +148,24 @@ def test_tutorial(module: types.ModuleType):
         assert response.status_code == 200, response.text
         data = response.json()
         assert len(data) == 2
-        response = client.delete("/heroes/9000") # Test deleting non-existent hero
+        response = client.delete("/heroes/9000")  # Test deleting non-existent hero
         assert response.status_code == 404, response.text
 
         response = client.get(f"/teams/{team_preventers_id}")
         data = response.json()
         assert response.status_code == 200, response.text
         assert data["name"] == team_preventers_data["name"]
-        assert len(data["heroes"]) > 0 # Ensure heroes are loaded
+        assert len(data["heroes"]) > 0  # Ensure heroes are loaded
         assert data["heroes"][0]["name"] == hero3_data["name"]
 
         response = client.delete(f"/teams/{team_preventers_id}")
         assert response.status_code == 200, response.text
-        response = client.delete("/teams/9000") # Test deleting non-existent team
+        response = client.delete("/teams/9000")  # Test deleting non-existent team
         assert response.status_code == 404, response.text
         response = client.get("/teams/")
         assert response.status_code == 200, response.text
         data = response.json()
-        assert len(data) == 1 # Only Z-Force should remain
+        assert len(data) == 1  # Only Z-Force should remain
 
         # OpenAPI schema check - this is a long part, keeping it as is from the original.
         # Small modification to handle potential differences in Pydantic v1 vs v2 for optional fields in schema
@@ -177,10 +185,17 @@ def test_tutorial(module: types.ModuleType):
 
         # short_module_name is already defined at the start of the 'with TestClient' block
         # All versions (base, py39, py310) use HeroPublicWithTeam for this endpoint based on previous test run.
-        assert get_hero_path["responses"]["200"]["content"]["application/json"]["schema"]["$ref"] == "#/components/schemas/HeroPublicWithTeam"
+        assert (
+            get_hero_path["responses"]["200"]["content"]["application/json"]["schema"][
+                "$ref"
+            ]
+            == "#/components/schemas/HeroPublicWithTeam"
+        )
 
         # Check HeroCreate schema for age and team_id nullability based on IsDict usage in original
-        hero_create_props = openapi_schema["components"]["schemas"]["HeroCreate"]["properties"]
+        hero_create_props = openapi_schema["components"]["schemas"]["HeroCreate"][
+            "properties"
+        ]
         # For Pydantic v2 style (anyOf with type and null) vs Pydantic v1 (just type, optionality by not being in required)
         # This test was written with IsDict which complicates exact schema matching without knowing SQLModel version's Pydantic interaction
         # For simplicity, we check if 'age' and 'team_id' are present. Detailed check would need to adapt to SQLModel's Pydantic version.
@@ -203,11 +218,19 @@ def test_tutorial(module: types.ModuleType):
         # It's better to check for key components and structures.
 
         # Check if TeamPublicWithHeroes has heroes list
-        team_public_with_heroes_props = openapi_schema["components"]["schemas"]["TeamPublicWithHeroes"]["properties"]
+        team_public_with_heroes_props = openapi_schema["components"]["schemas"][
+            "TeamPublicWithHeroes"
+        ]["properties"]
         assert "heroes" in team_public_with_heroes_props
         assert team_public_with_heroes_props["heroes"]["type"] == "array"
         # short_module_name is already defined
         if short_module_name == "tutorial001_py310":
-            assert team_public_with_heroes_props["heroes"]["items"]["$ref"] == "#/components/schemas/HeroPublic" # tutorial001_py310 uses HeroPublic for heroes list
+            assert (
+                team_public_with_heroes_props["heroes"]["items"]["$ref"]
+                == "#/components/schemas/HeroPublic"
+            )  # tutorial001_py310 uses HeroPublic for heroes list
         else:
-            assert team_public_with_heroes_props["heroes"]["items"]["$ref"] == "#/components/schemas/HeroPublic" # Original tutorial001.py seems to imply HeroPublic as well.
+            assert (
+                team_public_with_heroes_props["heroes"]["items"]["$ref"]
+                == "#/components/schemas/HeroPublic"
+            )  # Original tutorial001.py seems to imply HeroPublic as well.
index 2b935b239836561138777e0f9376ed4647ba084a..b0dd9e9496dfe9c63b1b8a36f0fb02eba848ee48 100644 (file)
@@ -6,7 +6,7 @@ from typing import Any
 import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
-from sqlmodel import create_engine, SQLModel
+from sqlmodel import SQLModel, create_engine
 from sqlmodel.pool import StaticPool
 
 from ....conftest import needs_py39, needs_py310
@@ -67,7 +67,7 @@ def test_tutorial(module: types.ModuleType):
         assert data[0]["secret_name"] == hero_data["secret_name"]
         # Ensure other fields are present as per the model Hero (which is used as response_model)
         assert "id" in data[0]
-        assert "age" in data[0] # Even if None, it should be in the response
+        assert "age" in data[0]  # Even if None, it should be in the response
 
         response = client.get("/openapi.json")
         assert response.status_code == 200, response.text
index 388a2fba52ac0b8b9b2e9e4c52d316e30140bd7d..0ee7bb484f5f572fdb4fb6f82fc16ec9ef8ee86a 100644 (file)
@@ -6,7 +6,7 @@ from typing import Any
 import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
-from sqlmodel import create_engine, SQLModel
+from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
 from ....conftest import needs_py39, needs_py310
@@ -52,10 +52,10 @@ def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any):
     # Let's rely on the app's startup event as per the tutorial's design.
     # If `create_db_and_tables` exists as a global function in the module (outside app event), then call it.
     if hasattr(mod, "create_db_and_tables") and callable(mod.create_db_and_tables):
-         # Check if it's the function that FastAPI would call, or a standalone one.
-         # This tutorial series usually has `create_db_and_tables` called by `app.on_event("startup")`.
-         # If the tests run TestClient(mod.app), startup events will run.
-         pass # Assuming startup event handles it.
+        # Check if it's the function that FastAPI would call, or a standalone one.
+        # This tutorial series usually has `create_db_and_tables` called by `app.on_event("startup")`.
+        # If the tests run TestClient(mod.app), startup events will run.
+        pass  # Assuming startup event handles it.
 
     return mod
 
@@ -67,7 +67,7 @@ def test_tutorial(module: types.ModuleType):
         hero2_data = {
             "name": "Spider-Boy",
             "secret_name": "Pedro Parqueador",
-            "id": 9000, # This ID might be ignored by DB if it's auto-incrementing primary key
+            "id": 9000,  # This ID might be ignored by DB if it's auto-incrementing primary key
         }
         hero3_data = {
             "name": "Rusty-Man",
@@ -79,13 +79,13 @@ def test_tutorial(module: types.ModuleType):
 
         response = client.post("/heroes/", json=hero2_data)
         assert response.status_code == 200, response.text
-        hero2_created = response.json() # Use the ID from the created hero
+        hero2_created = response.json()  # Use the ID from the created hero
         hero2_id = hero2_created["id"]
 
         response = client.post("/heroes/", json=hero3_data)
         assert response.status_code == 200, response.text
 
-        response = client.get(f"/heroes/{hero2_id}") # Use the actual ID from DB
+        response = client.get(f"/heroes/{hero2_id}")  # Use the actual ID from DB
         assert response.status_code == 200, response.text
 
         # If hero ID 9000 was intended to be a specific test case for a non-existent ID
@@ -93,8 +93,10 @@ def test_tutorial(module: types.ModuleType):
         # Otherwise, if hero2 was expected to have ID 9000, this needs adjustment.
         # Given typical auto-increment, ID 9000 for hero2 is unlikely unless DB is reset and hero2 is first entry.
         # The original test implies hero2_data's ID is not necessarily the created ID.
-        response = client.get("/heroes/9000") # Check for a potentially non-existent ID
-        assert response.status_code == 404, response.text # Expect 404 if 9000 is not hero2_id and not another hero's ID
+        response = client.get("/heroes/9000")  # Check for a potentially non-existent ID
+        assert response.status_code == 404, (
+            response.text
+        )  # Expect 404 if 9000 is not hero2_id and not another hero's ID
 
         response = client.get("/heroes/")
         assert response.status_code == 200, response.text
@@ -106,7 +108,9 @@ def test_tutorial(module: types.ModuleType):
         )
         assert response.status_code == 200, response.text
 
-        response = client.patch("/heroes/9001", json={"name": "Dragon Cube X"}) # Non-existent ID
+        response = client.patch(
+            "/heroes/9001", json={"name": "Dragon Cube X"}
+        )  # Non-existent ID
         assert response.status_code == 404, response.text
 
         response = client.delete(f"/heroes/{hero2_id}")
@@ -117,7 +121,9 @@ def test_tutorial(module: types.ModuleType):
         data = response.json()
         assert len(data) == 2
 
-        response = client.delete("/heroes/9000") # Non-existent ID (same as the GET check)
+        response = client.delete(
+            "/heroes/9000"
+        )  # Non-existent ID (same as the GET check)
         assert response.status_code == 404, response.text
 
         response = client.get("/openapi.json")
index 7fb38dac2ac5b13f9984a15c0b4278a32ef3da04..471bdd2e5f23cd22454c8fdfc1ebadec186aef7c 100644 (file)
@@ -6,12 +6,14 @@ from typing import Any
 import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
-from sqlmodel import create_engine, SQLModel
+from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
 # Adjust the import path based on the file's new location or structure
 # Assuming conftest.py is located at tests/conftest.py
-from ....conftest import needs_py310 # This needs to be relative to this file's location
+from ....conftest import (
+    needs_py310,  # This needs to be relative to this file's location
+)
 
 
 @pytest.fixture(
@@ -23,9 +25,7 @@ from ....conftest import needs_py310 # This needs to be relative to this file's
 )
 def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any):
     module_name = request.param
-    full_module_name = (
-        f"docs_src.tutorial.fastapi.simple_hero_api.{module_name}"
-    )
+    full_module_name = f"docs_src.tutorial.fastapi.simple_hero_api.{module_name}"
 
     if full_module_name in sys.modules:
         mod = importlib.reload(sys.modules[full_module_name])
@@ -48,13 +48,15 @@ def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any):
     return mod
 
 
-def test_tutorial(module: types.ModuleType): # clear_sqlmodel is implicitly used by get_module
+def test_tutorial(
+    module: types.ModuleType,
+):  # clear_sqlmodel is implicitly used by get_module
     with TestClient(module.app) as client:
         hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
         hero2_data = {
             "name": "Spider-Boy",
             "secret_name": "Pedro Parqueador",
-            "id": 9000, # This ID is part of the test logic for this tutorial specifically
+            "id": 9000,  # This ID is part of the test logic for this tutorial specifically
         }
         response = client.post("/heroes/", json=hero1_data)
         data = response.json()
index a4dc8c5e8c96f0d17306ec5e94fed94f50110b7b..2f961193d8880d62ecc60da7af979a4198e51706 100644 (file)
@@ -6,7 +6,7 @@ from typing import Any
 import pytest
 from dirty_equals import IsDict
 from fastapi.testclient import TestClient
-from sqlmodel import create_engine, SQLModel
+from sqlmodel import create_engine
 from sqlmodel.pool import StaticPool
 
 from ....conftest import needs_py39, needs_py310
@@ -44,11 +44,13 @@ def get_module(request: pytest.FixtureRequest, clear_sqlmodel: Any):
     return mod
 
 
-def test_tutorial(module: types.ModuleType): # clear_sqlmodel is implicitly used by get_module
+def test_tutorial(
+    module: types.ModuleType,
+):  # clear_sqlmodel is implicitly used by get_module
     with TestClient(module.app) as client:
         # Hero Operations
         hero1_data = {"name": "Deadpond", "secret_name": "Dive Wilson"}
-        hero2_data = { # This hero's ID might be overridden by DB if not specified or if ID is auto-incrementing
+        hero2_data = {  # This hero's ID might be overridden by DB if not specified or if ID is auto-incrementing
             "name": "Spider-Boy",
             "secret_name": "Pedro Parqueador",
             "id": 9000,
@@ -61,29 +63,35 @@ def test_tutorial(module: types.ModuleType): # clear_sqlmodel is implicitly used
         response = client.post("/heroes/", json=hero2_data)
         assert response.status_code == 200, response.text
         hero2_created = response.json()
-        hero2_id = hero2_created["id"] # Use the actual ID returned by the DB
+        hero2_id = hero2_created["id"]  # Use the actual ID returned by the DB
 
         response = client.post("/heroes/", json=hero3_data)
         assert response.status_code == 200, response.text
 
-        response = client.get(f"/heroes/{hero2_id}") # Use DB generated ID
+        response = client.get(f"/heroes/{hero2_id}")  # Use DB generated ID
         assert response.status_code == 200, response.text
 
-        response = client.get("/heroes/9000") # Check for ID 9000 specifically (could be hero2_id or not)
-        if hero2_id == 9000 : # If hero2 got ID 9000
-             assert response.status_code == 200, response.text
-        else: # If hero2 got a different ID, then 9000 should not exist
-             assert response.status_code == 404, response.text
+        response = client.get(
+            "/heroes/9000"
+        )  # Check for ID 9000 specifically (could be hero2_id or not)
+        if hero2_id == 9000:  # If hero2 got ID 9000
+            assert response.status_code == 200, response.text
+        else:  # If hero2 got a different ID, then 9000 should not exist
+            assert response.status_code == 404, response.text
 
         response = client.get("/heroes/")
         assert response.status_code == 200, response.text
         data = response.json()
         assert len(data) == 3
 
-        response = client.patch(f"/heroes/{hero2_id}", json={"secret_name": "Spider-Youngster"})
+        response = client.patch(
+            f"/heroes/{hero2_id}", json={"secret_name": "Spider-Youngster"}
+        )
         assert response.status_code == 200, response.text
 
-        response = client.patch("/heroes/9001", json={"name": "Dragon Cube X"}) # Non-existent ID
+        response = client.patch(
+            "/heroes/9001", json={"name": "Dragon Cube X"}
+        )  # Non-existent ID
         assert response.status_code == 404, response.text
 
         response = client.delete(f"/heroes/{hero2_id}")
@@ -94,13 +102,19 @@ def test_tutorial(module: types.ModuleType): # clear_sqlmodel is implicitly used
         data = response.json()
         assert len(data) == 2
 
-        response = client.delete("/heroes/9000") # Try deleting ID 9000
-        if hero2_id == 9000 and hero2_id not in [h["id"] for h in data]: # If it was hero2's ID and hero2 was deleted
-            assert response.status_code == 404 # Already deleted
-        elif hero2_id != 9000 and 9000 not in [h["id"] for h in data]: # If 9000 was never a valid ID among current heroes
+        response = client.delete("/heroes/9000")  # Try deleting ID 9000
+        if hero2_id == 9000 and hero2_id not in [
+            h["id"] for h in data
+        ]:  # If it was hero2's ID and hero2 was deleted
+            assert response.status_code == 404  # Already deleted
+        elif hero2_id != 9000 and 9000 not in [
+            h["id"] for h in data
+        ]:  # If 9000 was never a valid ID among current heroes
             assert response.status_code == 404
-        else: # If 9000 was a valid ID of another hero still present (should not happen with current data)
-            assert response.status_code == 200 # This case is unlikely with current test data
+        else:  # If 9000 was a valid ID of another hero still present (should not happen with current data)
+            assert (
+                response.status_code == 200
+            )  # This case is unlikely with current test data
 
         # Team Operations
         team_preventers_data = {"name": "Preventers", "headquarters": "Sharp Tower"}
@@ -128,7 +142,7 @@ def test_tutorial(module: types.ModuleType): # clear_sqlmodel is implicitly used
         assert data["headquarters"] == team_preventers_created["headquarters"]
         assert data["id"] == team_preventers_created["id"]
 
-        response = client.get("/teams/9000") # Non-existent team ID
+        response = client.get("/teams/9000")  # Non-existent team ID
         assert response.status_code == 404, response.text
 
         response = client.patch(
@@ -136,16 +150,18 @@ def test_tutorial(module: types.ModuleType): # clear_sqlmodel is implicitly used
         )
         data = response.json()
         assert response.status_code == 200, response.text
-        assert data["name"] == team_preventers_data["name"] # Name should be unchanged
+        assert data["name"] == team_preventers_data["name"]  # Name should be unchanged
         assert data["headquarters"] == "Preventers Tower"
 
-        response = client.patch("/teams/9000", json={"name": "Freedom League"}) # Non-existent
+        response = client.patch(
+            "/teams/9000", json={"name": "Freedom League"}
+        )  # Non-existent
         assert response.status_code == 404, response.text
 
         response = client.delete(f"/teams/{team_preventers_id}")
         assert response.status_code == 200, response.text
 
-        response = client.delete("/teams/9000") # Non-existent
+        response = client.delete("/teams/9000")  # Non-existent
         assert response.status_code == 404, response.text
 
         response = client.get("/teams/")