Repository navigation
Add missing tests for sftp exceptions - #72456
Conversation
providers/sftp/src/airflow/providers/sftp/exceptions.py had no dedicated test module and was not covered indirectly. The only raise site for ConnectionNotOpenedException is the handle_connection_management decorator in the sftp hook, which was untested as well, so the new module drives that decorator against a stub hook and drops the OVERLOOKED_TESTS entry. Closes: apache#72268
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
|
The workflow runs on this PR have been sitting in Could a committer approve the workflow runs when convenient? Happy to fix whatever comes up once they do. This adds the missing exception tests requested in #72268. cc @jroachgolf84 |
Summary
exceptions.py in the sftp provider had no tests. Nothing in providers/*/tests/ imported it either, so it wasn't getting covered by accident.
There's not much point in testing the exception class by itself. The one place that raises it is the handle_connection_management decorator, which had no tests of its own, so this covers the decorator and picks up the exception on the way through.
The test walks through four cases. With no open connection and use_managed_conn=False, it raises, and the message points you at hook.get_managed_conn(). With a connection already open, it just delegates and returns. With use_managed_conn=True, it opens a managed connection instead of raising, and sets it on the hook for the length of the call. And the exception subclasses AirflowException, which is worth pinning down since anyone catching the base class is counting on it.
Everything runs against a stub hook, so you don't need an SFTP server to run it.
I also removed the OVERLOOKED_TESTS entry.
Closes: #72268
Test Plan
The four tests pass against
apache-airflow-providers-sftpon Airflow 3.3.1 / Python 3.12, importing the real decorator and exception.ruff checkandruff format --checkpass using Airflow's own ruff configuration.Was generative AI tooling used to co-author this PR?
Tests drafted with Claude Code (Opus 5); reviewed and verified by @vitorantoniazzi