-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Separate out creation of default Connections for tests and non-tests #52129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate out creation of default Connections for tests and non-tests #52129
Conversation
create_default_connections
to store in ENV vars too8ac2182
to
3ec02ac
Compare
This is fine, but, we should make the tests work without the DB and remove all "db_test" markers for them eventually, I think this is possible. If I understand correctly - you now create both DB and ENV vars, so it should be just a matter of running conditional code to "only" clear and set "env variables" when DB is not available in the common pytest plugin code. The common plugin code already works fine when there is no DB - but I think what it does it will skip creation of the default connections - but if you just change the common code to skip all DB parts but only set the env vars, then I belive none of the "get_connection" calls should even try to make a DB call and they should simply work when you set |
Yep! That is my goal too
@potiuk quite the opposite actually, i have extracted out logic to not create stuff on DB for tests. (Trying to get to complete coverage). Right now, for tests, it creates only default connections and regular connections on ENV only. That is precisely what you propose I believe. |
Cool. I misunderstood the 'double' creation :) . The key is to run those tests with |
Ah i see, I updated the PR desc a little later, you might have caught the older one! |
Compat is not easy to fix! |
Alright! Finally green |
related: #51873
Why?
The
create_default_connections
is a well known utility we use to setup the default connections in Airflow, be it for the breeze setup, test setup or generally, maybe in connections command too.While working on moving BaseHook to the task SDK, i happened to notice 100's if not 1000's of failures of the form:
This is partly due to the fact that
mock_supervisor_comms
fixture isn't injected into them, and second being the fact that even if it is, I have to addmock_supervisor_comms.send.return_value = conn_result
to each of those 1000 tests which is absolutely impractical.So, if i could make the
mock_supervisor_comms
asautouse
and have the tests utilitise the fact that Airflow does Env backend as default and create env's for those "default" connections, the tests would not only be faster because they perform env vs DB lookup (earlier) but also benefit from the fact that provider tests need not essentially use the DB at all. (or cannot in the longer run when we move them entirely to task SDK's execution flow)Changes Made
clear_db_connections
toclear_test_connections
Some more trivial examples here
breeze start-airflow --backend postgres --executor CeleryExecutor --dev-mode --db-reset --load-default-connections
still worksairflow connections list
still works and creates connections as needed^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in airflow-core/newsfragments.