From a7f174c54b1d8e9b41d58f412c103629664fa644 Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Sun, 1 Feb 2026 07:17:12 -0400 Subject: [PATCH 1/2] Replace asynctest with stdlib mock The asynctest package is unmaintained since 2020 and incompatible with Python 3.12+. Replace asynctest.TestSelector with a MagicMock using selectors.BaseSelector as its spec, which provides the same mock selector functionality needed by the asyncio reactor tests. Fixes #663 --- pyproject.toml | 1 - tests/unit/io/test_asyncioreactor.py | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1c195e1b77..e524051042 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,6 @@ dev = [ "cython>=3.2", "packaging>=25.0", "futurist", - "asynctest", "pyyaml", "numpy", "objgraph", diff --git a/tests/unit/io/test_asyncioreactor.py b/tests/unit/io/test_asyncioreactor.py index c189aa3d74..f3ed942090 100644 --- a/tests/unit/io/test_asyncioreactor.py +++ b/tests/unit/io/test_asyncioreactor.py @@ -1,7 +1,6 @@ AsyncioConnection, ASYNCIO_AVAILABLE = None, False try: from cassandra.io.asyncioreactor import AsyncioConnection - import asynctest ASYNCIO_AVAILABLE = True except (ImportError, SyntaxError, AttributeError): AsyncioConnection = None @@ -10,8 +9,8 @@ from tests import is_monkey_patched, connection_class from tests.unit.io.utils import TimerCallback, TimerTestMixin -from unittest.mock import patch - +from unittest.mock import patch, MagicMock +import selectors import unittest import time @@ -56,7 +55,7 @@ def setUp(self): socket_patcher.start() old_selector = AsyncioConnection._loop._selector - AsyncioConnection._loop._selector = asynctest.TestSelector() + AsyncioConnection._loop._selector = MagicMock(spec=selectors.BaseSelector) def reset_selector(): AsyncioConnection._loop._selector = old_selector From caf2f7ad1edcb145f9b43fe4d85a9e716ec2ff38 Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Sun, 1 Feb 2026 13:24:04 -0400 Subject: [PATCH 2/2] Fix flaky test_multi_timer_validation on Windows CI Increase timer tolerance from 150ms to 500ms to account for CI environments under heavy load, especially Windows during wheel building where timing can be significantly less precise. --- tests/unit/io/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/io/utils.py b/tests/unit/io/utils.py index 174137225a..f43224058c 100644 --- a/tests/unit/io/utils.py +++ b/tests/unit/io/utils.py @@ -128,8 +128,10 @@ def submit_and_wait_for_completion(unit_test, create_timer, start, end, incremen time.sleep(.1) # ensure they are all called back in a timely fashion + # Use a generous tolerance (500ms) to account for CI environments under heavy load, + # especially Windows during wheel building where timing can be significantly less precise for callback in completed_callbacks: - assert callback.expected_wait == pytest.approx(callback.get_wait_time(), abs=.15) + assert callback.expected_wait == pytest.approx(callback.get_wait_time(), abs=.5) def noop_if_monkey_patched(f):