From 4fca3d76ec9980b6271afdbd891d4bc33af56141 Mon Sep 17 00:00:00 2001 From: Carlos Date: Sun, 4 Jan 2026 11:53:25 +0100 Subject: [PATCH 1/2] fix: suppress AsyncMock RuntimeWarnings in Python 3.13+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Python 3.13+, MagicMock auto-detects async-like method names (commit, debug, warning, etc.) and returns AsyncMock objects. This causes RuntimeWarnings when these methods are called synchronously. This commit adds: - A warning filter to suppress "coroutine was never awaited" warnings - A setup_mock_g() helper for tests that need explicit MagicMock setup - Updated create_mock_db_query() to also set up g.log 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- tests/base.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/base.py b/tests/base.py index 10aa3c80..f15c81ab 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1,6 +1,7 @@ """Contains base test case with needed setup and helpers.""" import os +import warnings from collections import namedtuple from contextlib import contextmanager from unittest import mock @@ -22,6 +23,15 @@ TestResult, TestResultFile, TestStatus, TestType) from mod_upload.models import Platform, Upload +# Filter RuntimeWarning about coroutines from AsyncMock in Python 3.13+ +# This occurs when MagicMock auto-detects async-like method names (commit, debug, etc.) +# Must be set before test execution begins. +warnings.filterwarnings( + "ignore", + message="coroutine .* was never awaited", + category=RuntimeWarning +) + @contextmanager def provide_file_at_root(file_name, to_write=None, to_delete=True): @@ -47,6 +57,26 @@ def empty_github_token(): g.github['bot_token'] = original +def setup_mock_g(mock_g): + """ + Set up mock_g with explicit MagicMock objects to avoid AsyncMock warnings. + + In Python 3.13+, MagicMock returns AsyncMock for method calls that look + async-like (commit, debug, warning, etc.). This causes RuntimeWarnings + when the code calls these methods synchronously. + + This helper sets up explicit MagicMock objects for g.db and g.log to + prevent these warnings. + + :param mock_g: The mocked g object from @mock.patch + :return: mock_g for chaining + """ + from unittest.mock import MagicMock + mock_g.db = MagicMock() + mock_g.log = MagicMock() + return mock_g + + def create_mock_db_query(mock_g, extra_setup=None): """ Create a MagicMock for mock_g.db with common query chain setup. @@ -60,6 +90,7 @@ def create_mock_db_query(mock_g, extra_setup=None): """ from unittest.mock import MagicMock mock_g.db = MagicMock() + mock_g.log = MagicMock() # Also set up log to prevent AsyncMock warnings mock_query = MagicMock() mock_g.db.query.return_value = mock_query mock_query.filter.return_value = mock_query From 1b428403ced8a1c599722c14675583c6f0d8d838 Mon Sep 17 00:00:00 2001 From: Carlos Date: Sun, 4 Jan 2026 13:27:49 +0100 Subject: [PATCH 2/2] fix: use MockStatus object instead of dict in test_webhook_pr_closed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code in mod_ci/controllers.py:1785 expects status objects with a .context attribute, but the test was returning dictionaries. This worked in earlier Python versions but fails in Python 3.14. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- tests/test_ci/test_controllers.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test_ci/test_controllers.py b/tests/test_ci/test_controllers.py index f1c4ba74..03ff6c72 100644 --- a/tests/test_ci/test_controllers.py +++ b/tests/test_ci/test_controllers.py @@ -38,6 +38,13 @@ def __init__(self, platform): self.value = 'linux' +class MockStatus: + """Mock GitHub commit status object.""" + + def __init__(self, context): + self.context = context + + class MockFork: """Mock fork object.""" @@ -781,8 +788,10 @@ def __init__(self): self.commit = "test" mock_test.query.filter.return_value.all.return_value = [MockTest()] + # Use MockStatus object instead of dict - code expects .context attribute + # Use 'linux' to match MockPlatform.value mock_repo.return_value.get_commit.return_value.get_statuses.return_value = [ - {"context": f"CI - {platform_name}"}] + MockStatus("CI - linux")] data = {'action': 'closed', 'pull_request': {'number': 1234, 'draft': False}}