Browse Source

remove deprecated event warnings and TODOs

pull/14773/head
Pravin Kamble 6 months ago
parent
commit
157aa23b14
  1. 2
      tests/test_tutorial/test_events/test_tutorial001.py
  2. 2
      tests/test_tutorial/test_events/test_tutorial002.py
  3. 8
      tests/test_tutorial/test_sql_databases/test_tutorial001.py
  4. 20
      tests/test_tutorial/test_sql_databases/test_tutorial002.py
  5. 5
      tests/test_tutorial/test_testing/test_tutorial003.py

2
tests/test_tutorial/test_events/test_tutorial001.py

@ -5,8 +5,8 @@ from fastapi.testclient import TestClient
@pytest.fixture(name="app", scope="module") @pytest.fixture(name="app", scope="module")
def get_app(): def get_app():
with pytest.warns(DeprecationWarning):
from docs_src.events.tutorial001_py39 import app from docs_src.events.tutorial001_py39 import app
yield app yield app

2
tests/test_tutorial/test_events/test_tutorial002.py

@ -5,8 +5,8 @@ from fastapi.testclient import TestClient
@pytest.fixture(name="app", scope="module") @pytest.fixture(name="app", scope="module")
def get_app(): def get_app():
with pytest.warns(DeprecationWarning):
from docs_src.events.tutorial002_py39 import app from docs_src.events.tutorial002_py39 import app
yield app yield app

8
tests/test_tutorial/test_sql_databases/test_tutorial001.py

@ -1,5 +1,4 @@
import importlib import importlib
import warnings
import pytest import pytest
from dirty_equals import IsInt from dirty_equals import IsInt
@ -30,9 +29,6 @@ def clear_sqlmodel():
) )
def get_client(request: pytest.FixtureRequest): def get_client(request: pytest.FixtureRequest):
clear_sqlmodel() clear_sqlmodel()
# TODO: remove when updating SQL tutorial to use new lifespan API
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
mod = importlib.import_module(f"docs_src.sql_databases.{request.param}") mod = importlib.import_module(f"docs_src.sql_databases.{request.param}")
clear_sqlmodel() clear_sqlmodel()
importlib.reload(mod) importlib.reload(mod)
@ -48,10 +44,6 @@ def get_client(request: pytest.FixtureRequest):
def test_crud_app(client: TestClient): def test_crud_app(client: TestClient):
# TODO: this warns that SQLModel.from_orm is deprecated in Pydantic v1, refactor
# this if using obj.model_validate becomes independent of Pydantic v2
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
# No heroes before creating # No heroes before creating
response = client.get("heroes/") response = client.get("heroes/")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text

20
tests/test_tutorial/test_sql_databases/test_tutorial002.py

@ -1,5 +1,4 @@
import importlib import importlib
import warnings
import pytest import pytest
from dirty_equals import IsInt from dirty_equals import IsInt
@ -30,9 +29,6 @@ def clear_sqlmodel():
) )
def get_client(request: pytest.FixtureRequest): def get_client(request: pytest.FixtureRequest):
clear_sqlmodel() clear_sqlmodel()
# TODO: remove when updating SQL tutorial to use new lifespan API
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
mod = importlib.import_module(f"docs_src.sql_databases.{request.param}") mod = importlib.import_module(f"docs_src.sql_databases.{request.param}")
clear_sqlmodel() clear_sqlmodel()
importlib.reload(mod) importlib.reload(mod)
@ -48,10 +44,6 @@ def get_client(request: pytest.FixtureRequest):
def test_crud_app(client: TestClient): def test_crud_app(client: TestClient):
# TODO: this warns that SQLModel.from_orm is deprecated in Pydantic v1, refactor
# this if using obj.model_validate becomes independent of Pydantic v2
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
# No heroes before creating # No heroes before creating
response = client.get("heroes/") response = client.get("heroes/")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
@ -68,20 +60,14 @@ def test_crud_app(client: TestClient):
}, },
) )
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == snapshot( assert response.json() == snapshot({"age": 30, "id": IsInt(), "name": "Dead Pond"})
{"age": 30, "id": IsInt(), "name": "Dead Pond"} assert response.json()["id"] != 9000, "The ID should be generated by the database"
)
assert response.json()["id"] != 9000, (
"The ID should be generated by the database"
)
# Read a hero # Read a hero
hero_id = response.json()["id"] hero_id = response.json()["id"]
response = client.get(f"/heroes/{hero_id}") response = client.get(f"/heroes/{hero_id}")
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.json() == snapshot( assert response.json() == snapshot({"name": "Dead Pond", "age": 30, "id": IsInt()})
{"name": "Dead Pond", "age": 30, "id": IsInt()}
)
# Read all heroes # Read all heroes
# Create more heroes first # Create more heroes first

5
tests/test_tutorial/test_testing/test_tutorial003.py

@ -1,7 +1,4 @@
import pytest
def test_main(): def test_main():
with pytest.warns(DeprecationWarning):
from docs_src.app_testing.tutorial003_py39 import test_read_items from docs_src.app_testing.tutorial003_py39 import test_read_items
test_read_items() test_read_items()

Loading…
Cancel
Save