Skip to content

Commit 6e7e4bb

Browse files
authored
Cleaning up sessions after each test (#11)
1 parent 7789567 commit 6e7e4bb

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

arangoasync/connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ async def process_request(self, request: Request) -> Response:
8181
ConnectionAbortedError: If can't connect to host(s) within limit.
8282
"""
8383

84-
ex_host_index = -1
8584
host_index = self._host_resolver.get_host_index()
8685
for tries in range(self._host_resolver.max_tries):
8786
try:

tests/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dataclasses import dataclass
22

33
import pytest
4+
import pytest_asyncio
45

56

67
@dataclass
@@ -57,3 +58,18 @@ def password():
5758
@pytest.fixture(autouse=False)
5859
def sys_db_name():
5960
return global_data.sys_db_name
61+
62+
63+
@pytest_asyncio.fixture
64+
async def client_session():
65+
sessions = []
66+
67+
def get_client_session(client, url):
68+
s = client.create_session(url)
69+
sessions.append(s)
70+
return s
71+
72+
yield get_client_session
73+
74+
for session in sessions:
75+
await session.close()

tests/test_connection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99

1010
@pytest.mark.asyncio
11-
async def test_BasicConnection_ping_failed(url, sys_db_name):
11+
async def test_BasicConnection_ping_failed(client_session, url, sys_db_name):
1212
client = AioHTTPClient()
13-
session = client.create_session(url)
13+
session = client_session(client, url)
1414
resolver = DefaultHostResolver(1)
1515

1616
connection = BasicConnection(
@@ -22,13 +22,14 @@ async def test_BasicConnection_ping_failed(url, sys_db_name):
2222

2323
with pytest.raises(ServerConnectionError):
2424
await connection.ping()
25-
await session.close()
2625

2726

2827
@pytest.mark.asyncio
29-
async def test_BasicConnection_ping_success(url, sys_db_name, root, password):
28+
async def test_BasicConnection_ping_success(
29+
client_session, url, sys_db_name, root, password
30+
):
3031
client = AioHTTPClient()
31-
session = client.create_session(url)
32+
session = client_session(client, url)
3233
resolver = DefaultHostResolver(1)
3334

3435
connection = BasicConnection(
@@ -41,4 +42,3 @@ async def test_BasicConnection_ping_success(url, sys_db_name, root, password):
4142

4243
status_code = await connection.ping()
4344
assert status_code == 200
44-
await session.close()

tests/test_http.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,21 @@ def test_DefaultHTTPClient():
1313

1414

1515
@pytest.mark.asyncio
16-
async def test_AioHTTPClient_wrong_url():
16+
async def test_AioHTTPClient_wrong_url(client_session):
1717
client = AioHTTPClient()
18-
session = client.create_session("http://www.fasdfdsafadawe3523523532plmcom.tgzs")
18+
session = client_session(client, "http://localhost:0000")
1919
request = Request(
2020
method=Method.GET,
2121
endpoint="/_api/version",
2222
)
2323
with pytest.raises(ClientConnectionError):
2424
await client.send_request(session, request)
25-
await session.close()
2625

2726

2827
@pytest.mark.asyncio
29-
async def test_AioHTTPClient_simple_request(url):
28+
async def test_AioHTTPClient_simple_request(client_session, url):
3029
client = AioHTTPClient()
31-
session = client.create_session(url)
30+
session = client_session(client, url)
3231
request = Request(
3332
method=Method.GET,
3433
endpoint="/_api/version",
@@ -38,13 +37,12 @@ async def test_AioHTTPClient_simple_request(url):
3837
assert response.url == f"{url}/_api/version"
3938
assert response.status_code == 401
4039
assert response.status_text == "Unauthorized"
41-
await session.close()
4240

4341

4442
@pytest.mark.asyncio
45-
async def test_AioHTTPClient_auth_pass(url, root, password):
43+
async def test_AioHTTPClient_auth_pass(client_session, url, root, password):
4644
client = AioHTTPClient()
47-
session = client.create_session(url)
45+
session = client_session(client, url)
4846
request = Request(
4947
method=Method.GET,
5048
endpoint="/_api/version",
@@ -55,4 +53,3 @@ async def test_AioHTTPClient_auth_pass(url, root, password):
5553
assert response.url == f"{url}/_api/version"
5654
assert response.status_code == 200
5755
assert response.status_text == "OK"
58-
await session.close()

0 commit comments

Comments
 (0)