Skip to content

Commit 55d0e0d

Browse files
authored
Fix asyncio warnings/markers. (opensearch-project#574)
* Fix asyncio warnings/markers. Signed-off-by: dblock <dblock@amazon.com> * Allow some flexibility in codecov. Signed-off-by: dblock <dblock@amazon.com> --------- Signed-off-by: dblock <dblock@amazon.com>
1 parent d8dc547 commit 55d0e0d

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

.github/codecov.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
threshold: 0.1%

test_opensearchpy/test_async/test_http_connection.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@
3030

3131
import mock
3232
import pytest
33-
from _pytest.mark.structures import MarkDecorator
3433
from multidict import CIMultiDict
3534

3635
from opensearchpy._async._extra_imports import aiohttp # type: ignore
3736
from opensearchpy._async.compat import get_running_loop
3837
from opensearchpy.connection.http_async import AsyncHttpConnection
3938

40-
pytestmark: MarkDecorator = pytest.mark.asyncio
41-
4239

4340
class TestAsyncHttpConnection:
4441
def test_auth_as_tuple(self) -> None:
@@ -60,6 +57,7 @@ def auth_fn() -> None:
6057
c = AsyncHttpConnection(http_auth=auth_fn)
6158
assert callable(c._http_auth)
6259

60+
@pytest.mark.asyncio # type: ignore
6361
@mock.patch("aiohttp.ClientSession.request", new_callable=mock.Mock)
6462
async def test_basicauth_in_request_session(self, mock_request: Any) -> None:
6563
async def do_request(*args: Any, **kwargs: Any) -> Any:
@@ -91,6 +89,7 @@ async def do_request(*args: Any, **kwargs: Any) -> Any:
9189
fingerprint=None,
9290
)
9391

92+
@pytest.mark.asyncio # type: ignore
9493
@mock.patch("aiohttp.ClientSession.request", new_callable=mock.Mock)
9594
async def test_callable_in_request_session(self, mock_request: Any) -> None:
9695
def auth_fn(*args: Any, **kwargs: Any) -> Any:

test_opensearchpy/test_async/test_plugins_client.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@
88
# Modifications Copyright OpenSearch Contributors. See
99
# GitHub history for details.
1010

11-
from unittest import TestCase
11+
12+
import warnings
13+
14+
import pytest
15+
from _pytest.mark.structures import MarkDecorator
1216

1317
from opensearchpy._async.client import AsyncOpenSearch
1418

19+
pytestmark: MarkDecorator = pytest.mark.asyncio
20+
1521

16-
class TestPluginsClient(TestCase):
22+
class TestPluginsClient:
1723
async def test_plugins_client(self) -> None:
18-
with self.assertWarns(Warning) as w:
24+
with warnings.catch_warnings(record=True) as w:
1925
client = AsyncOpenSearch()
2026
# testing double-init here
2127
client.plugins.__init__(client) # type: ignore
22-
self.assertEqual(
23-
str(w.warnings[0].message),
24-
"Cannot load `alerting` directly to AsyncOpenSearch as it already exists. Use `AsyncOpenSearch.plugin.alerting` instead.",
28+
assert (
29+
str(w[0].message)
30+
== "Cannot load `alerting` directly to AsyncOpenSearch as it already exists. Use `AsyncOpenSearch.plugin.alerting` instead."
2531
)

0 commit comments

Comments
 (0)