From 4ef3de646ef303ec5eb3f9f05da75cb919683f3d Mon Sep 17 00:00:00 2001 From: Thibaud Date: Mon, 2 Mar 2026 16:36:41 +0100 Subject: [PATCH] fix: use aiohttp ClientSession as a context manager --- wallabag_api/test_wallabag.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/wallabag_api/test_wallabag.py b/wallabag_api/test_wallabag.py index 042b5a9..65d131a 100644 --- a/wallabag_api/test_wallabag.py +++ b/wallabag_api/test_wallabag.py @@ -35,24 +35,24 @@ class TestWallabag: "original_url": "http://localhost", } - @pytest.fixture(scope="class") + @pytest.fixture(scope="function") async def configuration(self): return load_test_config(CONFIG_PATH) - @pytest.fixture(scope="class") + @pytest.fixture(scope="function") async def setup_class(self, configuration): access_token = await Wallabag.get_token(**configuration) - wallabag = Wallabag( - host=configuration["host"], - token=access_token, - client_id=configuration["client_id"], - client_secret=configuration["client_secret"], - aio_sess=aiohttp.ClientSession(), - ) - entry = await wallabag.post_entries(**self.entry_data) - yield wallabag, entry - await wallabag.delete_entries(entry["id"]) - await wallabag.aio_sess.close() + async with aiohttp.ClientSession() as session: + wallabag = Wallabag( + host=configuration["host"], + token=access_token, + client_id=configuration["client_id"], + client_secret=configuration["client_secret"], + aio_sess=session, + ) + entry = await wallabag.post_entries(**self.entry_data) + yield wallabag, entry + await wallabag.delete_entries(entry["id"]) @pytest.mark.asyncio async def test_get_token(self, configuration): @@ -105,7 +105,7 @@ class TestWallabag: entry_data = self.entry_data.copy() entry_data["url"] = "https://example.org" data = await wallabag.post_entries(**entry_data) - assert data is True + assert data assert isinstance(data["id"], int) await wallabag.delete_entries(data["id"]) @@ -133,7 +133,7 @@ class TestWallabag: entry_id = await self._create_entry(wallabag) assert isinstance(entry_id, int) data = await wallabag.delete_entries(entry_id) - assert data is True + assert data @pytest.mark.asyncio async def test_post_entry_tags(self, setup_class): @@ -143,7 +143,7 @@ class TestWallabag: tags = ["foo", "bar"] assert isinstance(tags, list) data = await wallabag.post_entry_tags(entry_id, tags) - assert data is True + assert data @pytest.mark.asyncio async def test_delete_entry_tag(self, setup_class):