-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Introducing fixture to create Connections
without DB in provider tests
#51930
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
Conversation
nice :) |
Hopefully we will be able to move most of the tests out of the "Db" zone this way :) |
WARNING: This one is going to get crazy with the number of changes. Planning to use env vars instead of DB. |
Yeah. It's going to be big. Maybe consider implementing a parallel solution and make an issue where others will convert provider by provider? That would be way more manageable (and if conversion is simple, would be rather fast). |
Let me create an MVP off of this and try to figure out if it needs that kind of splitting. |
Ok, getting there now. Probably really close this time. I am running into some errors with the telegram provider which I cannot seem to figure out.
Will add it part of TODO and handle there. |
@potiuk I am close with this one, do you wanna take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if CI is green.
providers/apache/kafka/tests/integration/apache/kafka/operators/test_consume.py
Show resolved
Hide resolved
Oh the compat tests! I made changes in #51953, which should fix this but I wonder how i can apply those here. |
OK, I decided to modify the fixture to use: Maybe if we see issues in future we can get back to CC @ashb |
Finally green! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIIIIICE!
Shall we merge ;) ? |
Merging it, thanks for the reviews @potiuk @ashb @jason810496! Yep @potiuk on it! |
Will work on the follow up items starting next week |
Let me see how much od the providers tests I can now move to be non-db tests :D.... That's on me |
After apache#51930, we can now remove "pytest.mark.db_test" in all providers that used db only to create connections. This PR is the "trial" attempt of doing so and it verifies that it is a viable thing to do. It: * removes all pytest.mark.db_test markers from airbyte * removes / reshuffles many pytest.mark.db_tests in amazon * adds pre-commit that we can use to guard that no new pytest.mark.db_test markers will be added in providers that we already cleaned up (for example airbyte) This PR, when merged will be followed up with an issue where we will ask contributors to apply the same approach to all the remaining providers - where I will describe in detail the process of removing the markers. This is part of the apache#42632 which has the long-term target of making all the provider tests non-db tests and simplifying our test setup.
First phase - amazon + airbyte here #52017 |
After apache#51930, we can now remove "pytest.mark.db_test" in all providers that used db only to create connections. This PR is the "trial" attempt of doing so and it verifies that it is a viable thing to do. It: * removes all pytest.mark.db_test markers from airbyte * removes / reshuffles many pytest.mark.db_tests in amazon * adds pre-commit that we can use to guard that no new pytest.mark.db_test markers will be added in providers that we already cleaned up (for example airbyte) This PR, when merged will be followed up with an issue where we will ask contributors to apply the same approach to all the remaining providers - where I will describe in detail the process of removing the markers. This is part of the apache#42632 which has the long-term target of making all the provider tests non-db tests and simplifying our test setup.
…le (#52017) After #51930, we can now remove "pytest.mark.db_test" in all providers that used db only to create connections. This PR is the "trial" attempt of doing so and it verifies that it is a viable thing to do. It: * removes all pytest.mark.db_test markers from airbyte * removes / reshuffles many pytest.mark.db_tests in amazon * adds pre-commit that we can use to guard that no new pytest.mark.db_test markers will be added in providers that we already cleaned up (for example airbyte) This PR, when merged will be followed up with an issue where we will ask contributors to apply the same approach to all the remaining providers - where I will describe in detail the process of removing the markers. This is part of the #42632 which has the long-term target of making all the provider tests non-db tests and simplifying our test setup.
@potiuk do you think we have to make changes to the system tests too? |
Well. Not really - those are regular DAGs, so they generally should not need (and cannot) access the DB. So we should adapt them too. |
On it! |
Why?
While working on moving basehook to task sdk (#51873), I realized that most providers set up their connections using
db.merge_conn()
with thousands of occurrences across the codebase.db.merge_conn()
is a utility that creates connections in the database for provider tests:My initial idea was to create a fixture that could intercept, find, and replace those calls with task SDK comms calls automatically. However, I decided against this approach because it didn't add much value and was not maintainable.
How?
Created a new pytest fixture that leveraged the fact that Airflow has a Env backend setup by default with precedence being higher than that of the database: https://airflow.apache.org/docs/apache-airflow/stable/howto/connection.html#storing-connections-in-environment-variables.
The
create_connection_without_db
fixture setsAIRFLOW_CONN_{conn_id.upper()}
toconn.get_uri()
which can be utilised during lookup.Benefits:
Effort involved:
There were various kinds of occurrences of
db.merge_conn
:setup_class
setup_method
setup_module
TODO
providers/telegram/tests/unit/telegram/hooks/test_telegram.py
Error:
^ 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.