Skip to content

Commit

Permalink
Fix DeprecationWarning from httpx
Browse files Browse the repository at this point in the history
Fix the following warning when running unit tests:

```
test/unit/webapps/test_request_scoped_sqlalchemy_sessions.py::test_request_scoped_sa_session_single_request
test/unit/webapps/test_request_scoped_sqlalchemy_sessions.py::test_request_scoped_sa_session_exception
test/unit/webapps/test_request_scoped_sqlalchemy_sessions.py::test_request_scoped_sa_session_concurrent_requests_sync
test/unit/webapps/test_request_scoped_sqlalchemy_sessions.py::test_request_scoped_sa_session_concurrent_requests_async
test/unit/webapps/test_request_scoped_sqlalchemy_sessions.py::test_request_scoped_sa_session_concurrent_requests_and_background_thread
  /usr/users/ga002/soranzon/software/nsoranzo_galaxy/.venv/lib/python3.10/site-packages/httpx/_client.py:1426: DeprecationWarning: The 'app' shortcut is now deprecated. Use the explicit style 'transport=ASGITransport(app=...)' instead.
```

See:

https://github.com/encode/httpx/blob/master/CHANGELOG.md#0270-21st-february-2024
  • Loading branch information
nsoranzo committed Aug 30, 2024
1 parent cf374eb commit ad8a029
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions test/unit/webapps/test_request_scoped_sqlalchemy_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
import pytest
from fastapi import FastAPI
from fastapi.param_functions import Depends
from httpx import AsyncClient
from httpx import (
ASGITransport,
AsyncClient,
)
from starlette_context import context as request_context

from galaxy.app_unittest_utils.galaxy_mock import MockApp
from galaxy.webapps.base.api import add_request_id_middleware

app = FastAPI()
add_request_id_middleware(app)
transport = ASGITransport(app=app)
GX_APP = None


Expand Down Expand Up @@ -96,7 +100,7 @@ def assert_scoped_session_is_thread_local(gx_app):

@pytest.mark.asyncio
async def test_request_scoped_sa_session_single_request():
async with AsyncClient(app=app, base_url="http://test") as client:
async with AsyncClient(base_url="http://test", transport=transport) as client:
response = await client.get("/")
assert response.status_code == 200
assert response.json() == {"msg": "Hello World"}
Expand All @@ -106,7 +110,7 @@ async def test_request_scoped_sa_session_single_request():

@pytest.mark.asyncio
async def test_request_scoped_sa_session_exception():
async with AsyncClient(app=app, base_url="http://test") as client:
async with AsyncClient(base_url="http://test", transport=transport) as client:
with pytest.raises(UnexpectedException):
await client.get("/internal_server_error")
assert GX_APP
Expand All @@ -115,7 +119,7 @@ async def test_request_scoped_sa_session_exception():

@pytest.mark.asyncio
async def test_request_scoped_sa_session_concurrent_requests_sync():
async with AsyncClient(app=app, base_url="http://test") as client:
async with AsyncClient(base_url="http://test", transport=transport) as client:
awaitables = (client.get("/sync_wait") for _ in range(10))
result = await asyncio.gather(*awaitables)
uuids = []
Expand All @@ -129,7 +133,7 @@ async def test_request_scoped_sa_session_concurrent_requests_sync():

@pytest.mark.asyncio
async def test_request_scoped_sa_session_concurrent_requests_async():
async with AsyncClient(app=app, base_url="http://test") as client:
async with AsyncClient(base_url="http://test", transport=transport) as client:
awaitables = (client.get("/async_wait") for _ in range(10))
result = await asyncio.gather(*awaitables)
uuids = []
Expand All @@ -147,7 +151,7 @@ async def test_request_scoped_sa_session_concurrent_requests_and_background_thre
target = functools.partial(assert_scoped_session_is_thread_local, GX_APP)
with concurrent.futures.ThreadPoolExecutor() as pool:
background_pool = loop.run_in_executor(pool, target)
async with AsyncClient(app=app, base_url="http://test") as client:
async with AsyncClient(base_url="http://test", transport=transport) as client:
awaitables = (client.get("/async_wait") for _ in range(10))
result = await asyncio.gather(*awaitables)
uuids = []
Expand Down

0 comments on commit ad8a029

Please sign in to comment.