From cda4a635b1ccd162d2025a922bb7b49197eaa614 Mon Sep 17 00:00:00 2001 From: JRoot Junior Date: Thu, 16 Nov 2023 01:47:23 +0200 Subject: [PATCH] #1320 Update pytest configuration and tests cleanup This commit modifies the pytest's configuration file, `pyproject.toml`, to remove filterwarnings settings. It also makes changes in various test files; the Redis isolation test is now using the provided `redis_storage` fixture instead of setting up its own connection, pytest.mark.filterwarnings is no longer used in `test_isolation.py` and `test_aiohttp_session.py` properly closes off sessions. --- pyproject.toml | 7 +++---- tests/conftest.py | 19 ++++--------------- .../test_session/test_aiohttp_session.py | 2 ++ tests/test_fsm/storage/test_isolation.py | 1 - 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0557223b..2ae2f1b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -237,10 +237,9 @@ asyncio_mode = "auto" testpaths = [ "tests", ] -filterwarnings = [ - "error", - "ignore::pytest.PytestUnraisableExceptionWarning", -] +#filterwarnings = [ +# "error", +#] [tool.coverage.run] branch = false diff --git a/tests/conftest.py b/tests/conftest.py index 1c72f386..3e063ff1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -38,7 +38,7 @@ def pytest_collection_modifyitems(config, items): raise UsageError(f"Invalid redis URI {redis_uri!r}: {e}") -@pytest.fixture(scope="session") +@pytest.fixture() def redis_server(request): redis_uri = request.config.getoption("--redis") return redis_uri @@ -73,20 +73,9 @@ async def memory_storage(): @pytest.fixture() @pytest.mark.redis -async def redis_isolation(redis_server): - if not redis_server: - pytest.skip("Redis is not available here") - isolation = RedisEventIsolation.from_url(redis_server) - try: - await isolation.redis.info() - except ConnectionError as e: - pytest.skip(str(e)) - try: - yield isolation - finally: - conn = await isolation.redis - await conn.flushdb() - await isolation.close() +async def redis_isolation(redis_storage): + isolation = redis_storage.create_isolation() + return isolation @pytest.fixture() diff --git a/tests/test_api/test_client/test_session/test_aiohttp_session.py b/tests/test_api/test_client/test_session/test_aiohttp_session.py index bc7aff83..6740dcc1 100644 --- a/tests/test_api/test_client/test_session/test_aiohttp_session.py +++ b/tests/test_api/test_client/test_session/test_aiohttp_session.py @@ -96,6 +96,8 @@ class TestAiohttpSession: await session.close() mocked_close.assert_called_once() + await session.close() + def test_build_form_data_with_data_only(self, bot: MockedBot): class TestMethod(TelegramMethod[bool]): __api_method__ = "test" diff --git a/tests/test_fsm/storage/test_isolation.py b/tests/test_fsm/storage/test_isolation.py index 60e240ae..f41a2b2c 100644 --- a/tests/test_fsm/storage/test_isolation.py +++ b/tests/test_fsm/storage/test_isolation.py @@ -18,7 +18,6 @@ def create_storage_key(bot: MockedBot): ], ) class TestIsolations: - @pytest.mark.filterwarnings("ignore::ResourceWarning") async def test_lock( self, isolation: BaseEventIsolation,