Repository navigation
fix: suppress AsyncMock RuntimeWarnings in Python 3.13+ - #999
Conversation
|
What about using a separate branch for this second commit? :) |
| warnings.filterwarnings( | ||
| "ignore", | ||
| message="coroutine .* was never awaited", | ||
| category=RuntimeWarning | ||
| ) |
There was a problem hiding this comment.
We probably want to do something about this in the future then, but I'm fine with suppressing them for now.
e6b3d68 to
4c6bcf9
Compare
|
You're right - this PR currently includes both the AsyncMock warning fix AND the SQLAlchemy 2.0 changes, which makes it messy. The SQLAlchemy 2.0 upgrade is already in PR #998. This PR should be rebased to only include the AsyncMock warning fixes once PR #998 is merged. Would you prefer I:
|
|
Rebase I'd say. GitHub can't do it. |
ebbf428 to
94dc99a
Compare
|
Please get rid of the SQLAlchemy commit, it still holds changes from the original PR that were changed afterwards... |
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 <noreply@anthropic.com>
94dc99a to
4fca3d7
Compare
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 <noreply@anthropic.com>
|



Summary
This PR fixes the RuntimeWarnings that appear when running tests with Python 3.13+:
Root cause
In Python 3.13+,
MagicMockautomatically returnsAsyncMockfor method calls that look async-like (such ascommit,debug,warning,error). When tests mock Flask'sgobject and the code callsg.db.commit()org.log.debug(...), Python warns that these coroutines were never awaited.Changes
warnings.filterwarnings()to suppress these specific warningssetup_mock_g()helper function for tests that need explicit MagicMock setupcreate_mock_db_query()to also set upg.logas a MagicMockTest plan
🤖 Generated with Claude Code