itz-puneet opened a new pull request, #72605:
URL: https://github.com/apache/airflow/pull/72605
closes: #72268
`providers/sftp/src/airflow/providers/sftp/exceptions.py` had no test module
and was not covered
indirectly either — nothing under any `providers/*/tests/` directory
imported it — so it sat on the
`OVERLOOKED_TESTS` allowlist in
`airflow-core/tests/unit/always/test_project_structure.py`.
The module declares a single exception, `ConnectionNotOpenedException`. As
the issue points out,
asserting the class declaration on its own would be worth very little, so
the tests target the
behaviour that raises it instead: the `handle_connection_management`
decorator in
`providers/sftp/src/airflow/providers/sftp/hooks/sftp.py`. That decorator is
the exception's only
raise site, and no test in `providers/sftp/tests/` exercised that branch
either.
What the new tests pin down:
- an unmanaged call (`use_managed_conn=False`) with no open connection raises
`ConnectionNotOpenedException`, and the message points the caller at
`hook.get_managed_conn()`
- an unmanaged call with a connection already open delegates through to the
wrapped function,
forwards its arguments, returns its result, and does not open a managed
connection
- a managed call (`use_managed_conn=True`) opens a managed connection
instead of raising, sets it on
the hook for the duration of the call, and releases it — including when
the wrapped call raises
- `ConnectionNotOpenedException` derives from `AirflowException`, which
matters because callers catch
the base class and narrowing it later would be a breaking change for them
The decorator runs against a small stub hook exposing only the three
attributes it touches
(`use_managed_conn`, `conn`, `get_managed_conn`), so the tests need no SFTP
server, no database and
no network, and run in milliseconds.
`providers/sftp/tests/unit/sftp/test_exceptions.py` is also removed from
`OVERLOOKED_TESTS`, per the
definition of done in the issue.
---
**Gen-AI disclosure:** I used an AI coding assistant while drafting these
tests. I reviewed the
decorator's behaviour against the source myself and checked each assertion
fails against a
deliberately broken decorator before submitting.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]