Skip to content

Conversation

@cfsmp3
Copy link
Contributor

@cfsmp3 cfsmp3 commented Jan 4, 2026

Summary

This PR fixes the RuntimeWarnings that appear when running tests with Python 3.13+:

RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Root cause

In Python 3.13+, MagicMock automatically returns AsyncMock for method calls that look async-like (such as commit, debug, warning, error). When tests mock Flask's g object and the code calls g.db.commit() or g.log.debug(...), Python warns that these coroutines were never awaited.

Changes

  • Add a warnings.filterwarnings() to suppress these specific warnings
  • Add setup_mock_g() helper function for tests that need explicit MagicMock setup
  • Update create_mock_db_query() to also set up g.log as a MagicMock

Test plan

  • All 402 tests pass
  • RuntimeWarnings are no longer displayed (was 48, now 0)

🤖 Generated with Claude Code

@canihavesomecoffee
Copy link
Member

What about using a separate branch for this second commit? :)

tests/base.py Outdated
Comment on lines 11 to 15
warnings.filterwarnings(
"ignore",
message="coroutine .* was never awaited",
category=RuntimeWarning
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to do something about this in the future then, but I'm fine with suppressing them for now.

@cfsmp3 cfsmp3 force-pushed the fix/async-mock-warnings branch 4 times, most recently from e6b3d68 to 4c6bcf9 Compare January 4, 2026 11:35
@cfsmp3
Copy link
Contributor Author

cfsmp3 commented Jan 4, 2026

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:

  1. Wait for PR chore(deps): upgrade SQLAlchemy from 1.4.41 to 2.0.45 #998 to merge first, then rebase this PR to only include the AsyncMock changes?
  2. Or close this PR and create a new clean one after chore(deps): upgrade SQLAlchemy from 1.4.41 to 2.0.45 #998 merges?

@canihavesomecoffee
Copy link
Member

Rebase I'd say. GitHub can't do it.

@cfsmp3 cfsmp3 force-pushed the fix/async-mock-warnings branch from ebbf428 to 94dc99a Compare January 4, 2026 12:10
@canihavesomecoffee
Copy link
Member

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 <[email protected]>
@cfsmp3 cfsmp3 force-pushed the fix/async-mock-warnings branch from 94dc99a to 4fca3d7 Compare January 4, 2026 12:20
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 <[email protected]>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 4, 2026

@canihavesomecoffee canihavesomecoffee merged commit b1e9efb into master Jan 4, 2026
6 checks passed
@cfsmp3 cfsmp3 deleted the fix/async-mock-warnings branch January 4, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants