fix: use aiohttp ClientSession as a context manager

This commit is contained in:
2026-03-02 16:36:41 +01:00
parent 9ee4f70428
commit 4ef3de646e

View File

@@ -35,24 +35,24 @@ class TestWallabag:
"original_url": "http://localhost", "original_url": "http://localhost",
} }
@pytest.fixture(scope="class") @pytest.fixture(scope="function")
async def configuration(self): async def configuration(self):
return load_test_config(CONFIG_PATH) return load_test_config(CONFIG_PATH)
@pytest.fixture(scope="class") @pytest.fixture(scope="function")
async def setup_class(self, configuration): async def setup_class(self, configuration):
access_token = await Wallabag.get_token(**configuration) access_token = await Wallabag.get_token(**configuration)
async with aiohttp.ClientSession() as session:
wallabag = Wallabag( wallabag = Wallabag(
host=configuration["host"], host=configuration["host"],
token=access_token, token=access_token,
client_id=configuration["client_id"], client_id=configuration["client_id"],
client_secret=configuration["client_secret"], client_secret=configuration["client_secret"],
aio_sess=aiohttp.ClientSession(), aio_sess=session,
) )
entry = await wallabag.post_entries(**self.entry_data) entry = await wallabag.post_entries(**self.entry_data)
yield wallabag, entry yield wallabag, entry
await wallabag.delete_entries(entry["id"]) await wallabag.delete_entries(entry["id"])
await wallabag.aio_sess.close()
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_get_token(self, configuration): async def test_get_token(self, configuration):
@@ -105,7 +105,7 @@ class TestWallabag:
entry_data = self.entry_data.copy() entry_data = self.entry_data.copy()
entry_data["url"] = "https://example.org" entry_data["url"] = "https://example.org"
data = await wallabag.post_entries(**entry_data) data = await wallabag.post_entries(**entry_data)
assert data is True assert data
assert isinstance(data["id"], int) assert isinstance(data["id"], int)
await wallabag.delete_entries(data["id"]) await wallabag.delete_entries(data["id"])
@@ -133,7 +133,7 @@ class TestWallabag:
entry_id = await self._create_entry(wallabag) entry_id = await self._create_entry(wallabag)
assert isinstance(entry_id, int) assert isinstance(entry_id, int)
data = await wallabag.delete_entries(entry_id) data = await wallabag.delete_entries(entry_id)
assert data is True assert data
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_post_entry_tags(self, setup_class): async def test_post_entry_tags(self, setup_class):
@@ -143,7 +143,7 @@ class TestWallabag:
tags = ["foo", "bar"] tags = ["foo", "bar"]
assert isinstance(tags, list) assert isinstance(tags, list)
data = await wallabag.post_entry_tags(entry_id, tags) data = await wallabag.post_entry_tags(entry_id, tags)
assert data is True assert data
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_delete_entry_tag(self, setup_class): async def test_delete_entry_tag(self, setup_class):