diff --git a/arangoasync/connection.py b/arangoasync/connection.py index bf6ef8a..0fdd2bc 100644 --- a/arangoasync/connection.py +++ b/arangoasync/connection.py @@ -81,7 +81,6 @@ async def process_request(self, request: Request) -> Response: ConnectionAbortedError: If can't connect to host(s) within limit. """ - ex_host_index = -1 host_index = self._host_resolver.get_host_index() for tries in range(self._host_resolver.max_tries): try: diff --git a/tests/conftest.py b/tests/conftest.py index f335bed..564786e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ from dataclasses import dataclass import pytest +import pytest_asyncio @dataclass @@ -57,3 +58,18 @@ def password(): @pytest.fixture(autouse=False) def sys_db_name(): return global_data.sys_db_name + + +@pytest_asyncio.fixture +async def client_session(): + sessions = [] + + def get_client_session(client, url): + s = client.create_session(url) + sessions.append(s) + return s + + yield get_client_session + + for session in sessions: + await session.close() diff --git a/tests/test_connection.py b/tests/test_connection.py index 6c98081..40a525d 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -8,9 +8,9 @@ @pytest.mark.asyncio -async def test_BasicConnection_ping_failed(url, sys_db_name): +async def test_BasicConnection_ping_failed(client_session, url, sys_db_name): client = AioHTTPClient() - session = client.create_session(url) + session = client_session(client, url) resolver = DefaultHostResolver(1) connection = BasicConnection( @@ -22,13 +22,14 @@ async def test_BasicConnection_ping_failed(url, sys_db_name): with pytest.raises(ServerConnectionError): await connection.ping() - await session.close() @pytest.mark.asyncio -async def test_BasicConnection_ping_success(url, sys_db_name, root, password): +async def test_BasicConnection_ping_success( + client_session, url, sys_db_name, root, password +): client = AioHTTPClient() - session = client.create_session(url) + session = client_session(client, url) resolver = DefaultHostResolver(1) connection = BasicConnection( @@ -41,4 +42,3 @@ async def test_BasicConnection_ping_success(url, sys_db_name, root, password): status_code = await connection.ping() assert status_code == 200 - await session.close() diff --git a/tests/test_http.py b/tests/test_http.py index e631586..341595b 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -13,22 +13,21 @@ def test_DefaultHTTPClient(): @pytest.mark.asyncio -async def test_AioHTTPClient_wrong_url(): +async def test_AioHTTPClient_wrong_url(client_session): client = AioHTTPClient() - session = client.create_session("http://www.fasdfdsafadawe3523523532plmcom.tgzs") + session = client_session(client, "http://localhost:0000") request = Request( method=Method.GET, endpoint="/_api/version", ) with pytest.raises(ClientConnectionError): await client.send_request(session, request) - await session.close() @pytest.mark.asyncio -async def test_AioHTTPClient_simple_request(url): +async def test_AioHTTPClient_simple_request(client_session, url): client = AioHTTPClient() - session = client.create_session(url) + session = client_session(client, url) request = Request( method=Method.GET, endpoint="/_api/version", @@ -38,13 +37,12 @@ async def test_AioHTTPClient_simple_request(url): assert response.url == f"{url}/_api/version" assert response.status_code == 401 assert response.status_text == "Unauthorized" - await session.close() @pytest.mark.asyncio -async def test_AioHTTPClient_auth_pass(url, root, password): +async def test_AioHTTPClient_auth_pass(client_session, url, root, password): client = AioHTTPClient() - session = client.create_session(url) + session = client_session(client, url) request = Request( method=Method.GET, endpoint="/_api/version", @@ -55,4 +53,3 @@ async def test_AioHTTPClient_auth_pass(url, root, password): assert response.url == f"{url}/_api/version" assert response.status_code == 200 assert response.status_text == "OK" - await session.close()