Skip to content

Commit 9f9678b

Browse files
romanlutzCopilot
andauthored
MAINT: Silence deprecation warnings in unit tests (microsoft#2108)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 34f0073 commit 9f9678b

6 files changed

Lines changed: 13 additions & 11 deletions

File tree

tests/unit/backend/test_api_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def test_list_attacks_rejects_invalid_converter_types_match(self, client: TestCl
648648

649649
response = client.get("/api/attacks?converter_types_match=garbage")
650650

651-
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
651+
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
652652

653653
def test_get_conversations_success(self, client: TestClient) -> None:
654654
"""Test getting attack conversations returns service response."""

tests/unit/backend/test_initializer_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def test_post_returns_422_for_invalid_name(
392392
response = client_with_custom_initializers_enabled.post(
393393
"/api/initializers", json={"name": bad_name, "script_content": _SAMPLE_SCRIPT}
394394
)
395-
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
395+
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
396396

397397
def test_post_returns_201_with_registered_initializer(
398398
self, client_with_custom_initializers_enabled: TestClient

tests/unit/backend/test_scenario_run_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_start_run_invalid_scenario_returns_400(self, client: TestClient) -> Non
9090
def test_start_run_missing_required_fields_returns_422(self, client: TestClient) -> None:
9191
"""Test that missing required fields returns 422."""
9292
response = client.post("/api/scenarios/runs", json={})
93-
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
93+
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
9494

9595
def test_start_run_with_all_options(self, client: TestClient) -> None:
9696
"""Test that all optional fields are accepted."""

tests/unit/prompt_target/target/test_openai_chat_target.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,9 @@ def mock_token_provider():
711711
assert callable(target._api_key)
712712
# Since sync provider is wrapped, _api_key is now async
713713
import asyncio
714+
import inspect
714715

715-
assert asyncio.iscoroutinefunction(target._api_key)
716+
assert inspect.iscoroutinefunction(target._api_key)
716717
assert asyncio.run(target._api_key()) == "mock-entra-token"
717718

718719

tests/unit/prompt_target/target/test_openai_target_auth.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the MIT license.
33

44
import asyncio
5+
import inspect
56
import os
67
from collections.abc import Callable
78
from unittest.mock import AsyncMock, MagicMock, patch
@@ -101,7 +102,7 @@ def sync_provider() -> str:
101102
return "sync-token"
102103

103104
target = _build_target(api_key=sync_provider)
104-
assert asyncio.iscoroutinefunction(target._api_key)
105+
assert inspect.iscoroutinefunction(target._api_key)
105106
# Verify the wrapper actually calls through
106107
token = asyncio.run(target._api_key())
107108
assert token == "sync-token"
@@ -142,7 +143,7 @@ def provider() -> str:
142143
return "sync-token"
143144

144145
result = ensure_async_token_provider(provider)
145-
assert asyncio.iscoroutinefunction(result)
146+
assert inspect.iscoroutinefunction(result)
146147
assert asyncio.run(result()) == "sync-token"
147148

148149
def test_non_callable_non_string_returned_as_is(self):

tests/unit/prompt_target/target/test_token_provider_wrapping.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT license.
33

4-
import asyncio
4+
import inspect
55
from unittest.mock import AsyncMock, patch
66

77
import pytest
@@ -32,7 +32,7 @@ async def async_token_provider():
3232

3333
result = ensure_async_token_provider(async_token_provider)
3434
assert result is async_token_provider
35-
assert asyncio.iscoroutinefunction(result)
35+
assert inspect.iscoroutinefunction(result)
3636

3737
def test_sync_token_provider_wrapped(self):
3838
"""Test that synchronous token providers are automatically wrapped."""
@@ -45,7 +45,7 @@ def sync_token_provider():
4545
# Should return a different callable (the wrapper)
4646
assert result is not sync_token_provider
4747
assert callable(result)
48-
assert asyncio.iscoroutinefunction(result)
48+
assert inspect.iscoroutinefunction(result)
4949

5050
async def test_wrapped_sync_provider_returns_correct_token(self):
5151
"""Test that wrapped synchronous token provider returns the correct token."""
@@ -147,7 +147,7 @@ def sync_token_provider():
147147
# The api_key should be a callable
148148
api_key_arg = call_kwargs["api_key"]
149149
assert callable(api_key_arg)
150-
assert asyncio.iscoroutinefunction(api_key_arg)
150+
assert inspect.iscoroutinefunction(api_key_arg)
151151

152152
# Verify the wrapped token provider returns correct value
153153
token = await api_key_arg()
@@ -234,7 +234,7 @@ def mock_sync_bearer_token_provider():
234234
call_kwargs = mock_openai.call_args[1]
235235
wrapped_provider = call_kwargs["api_key"]
236236

237-
assert asyncio.iscoroutinefunction(wrapped_provider)
237+
assert inspect.iscoroutinefunction(wrapped_provider)
238238

239239
# Verify it returns the correct token
240240
token = await wrapped_provider()

0 commit comments

Comments
 (0)