Fix SFTPHookAsync test fixture to return async context managers#66678
Merged
Conversation
After apache#64465 changed the production code from ``sftp = await ssh_conn.start_sftp_client()`` to ``async with ssh_conn.start_sftp_client() as sftp:`` (and likewise for ``sftp.open()``), the ``sftp_hook_mocked`` fixture in ``providers/sftp/tests/conftest.py`` started returning coroutines from those calls — ``AsyncMock(spec=SSHClientConnection)`` auto-makes ``start_sftp_client`` an ``AsyncMock`` whose call yields a coroutine, not an async context manager — and every ``TestSFTPHookAsync`` test that uses the fixture failed with ``TypeError: 'coroutine' object does not support the asynchronous context manager protocol``. In real asyncssh, both ``start_sftp_client()`` and ``SFTPClient.open()`` are decorated so a call returns an object that is both awaitable and async-context-manageable; the production code only uses the context-manager half. Override the auto-spec'd AsyncMocks with sync MagicMocks that return a context-manager mock with ``__aenter__`` / ``__aexit__`` configured. Restores 28 ``TestSFTPHookAsync`` tests in ``providers/sftp/tests/unit/sftp/hooks/test_sftp.py`` (blocking CI on unrelated PRs since apache#64465 merged).
Member
Author
|
RE-run with "all versions" |
jscheffl
approved these changes
May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR #64465 (SFTP async refactor) changed the production code from
await ssh_conn.start_sftp_client()toasync with ssh_conn.start_sftp_client() as sftp:(same forsftp.open()), but thesftp_hook_mockedfixture inproviders/sftp/tests/conftest.pywas still set up as if those methodswere awaited.
AsyncMock(spec=SSHClientConnection)auto-makesstart_sftp_clientanAsyncMockwhose call returns a coroutine — not an async contextmanager — so every
TestSFTPHookAsynctest inproviders/sftp/tests/unit/sftp/hooks/test_sftp.pyblew up with:In real asyncssh, both
SSHClientConnection.start_sftp_client()andSFTPClient.open()are decorated so a call returns an object that isboth awaitable and async-context-manageable. The production code only
uses the context-manager half. Override the auto-spec'd AsyncMocks with
sync
MagicMocks that return a context-manager mock with__aenter__/__aexit__configured.Test plan
TestSFTPHookAsynctests inproviders/sftp/tests/unit/sftp/hooks/test_sftp.pypass locallyagainst
upstream/main.prek runclean on the changed file.Blocking CI on unrelated PRs since #64465 merged — example failure:
https://github.com/apache/airflow/actions/runs/25638333348/job/75256444992?pr=65840
(PR #65840 only touches
docs-theme/breeze; the SFTP failures arepurely fixture rot).
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Opus 4.7 (1M context) following the guidelines