You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2024/02/14 10:42:45 UTC
(airflow) branch main updated: Avoid side-effects for providers-manager related tests (#37414)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 7461ac7277 Avoid side-effects for providers-manager related tests (#37414)
7461ac7277 is described below
commit 7461ac7277da4fc8f7e35169c67d342950a7f958
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Wed Feb 14 11:42:38 2024 +0100
Avoid side-effects for providers-manager related tests (#37414)
When running tests in v2-8-tests some of the tests failed with
package-name key not found in providers manager. This was because
some other tests modified dictionaries stored in ProvidersManager
and added there entries that missed the keys.
This PR adds a a new fixture `cleanup_providers_manager` - that will
reinitialize the ProvidersManager before the test and - more importantly
will clean it up after. This way all the entries added manually should
be removed for other tests and all the tests that do not explicitly
initialize providers manager should fail if they need it.
---
tests/always/test_providers_manager.py | 11 ++++-------
tests/api_connexion/endpoints/test_provider_endpoint.py | 2 +-
tests/cli/commands/test_info_command.py | 2 +-
tests/conftest.py | 12 ++++++++++++
4 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/tests/always/test_providers_manager.py b/tests/always/test_providers_manager.py
index 0687965571..515b10b3ea 100644
--- a/tests/always/test_providers_manager.py
+++ b/tests/always/test_providers_manager.py
@@ -39,14 +39,9 @@ from airflow.providers_manager import (
class TestProviderManager:
@pytest.fixture(autouse=True)
- def inject_fixtures(self, caplog):
+ def inject_fixtures(self, caplog, cleanup_providers_manager):
self._caplog = caplog
- @pytest.fixture(autouse=True, scope="function")
- def clean(self):
- """The tests depend on a clean state of a ProvidersManager."""
- ProvidersManager().__init__()
-
def test_providers_are_loaded(self):
with self._caplog.at_level(logging.WARNING):
provider_manager = ProvidersManager()
@@ -93,8 +88,9 @@ class TestProviderManager:
assert [] == [w.message for w in warning_records.list if "hook-class-names" in str(w.message)]
def test_warning_logs_generated(self):
+ providers_manager = ProvidersManager()
+ providers_manager._hooks_lazy_dict = LazyDictWithCache()
with self._caplog.at_level(logging.WARNING):
- providers_manager = ProvidersManager()
providers_manager._provider_dict["apache-airflow-providers-sftp"] = ProviderInfo(
version="0.0.1",
data={
@@ -165,6 +161,7 @@ class TestProviderManager:
def test_providers_manager_register_plugins(self):
providers_manager = ProvidersManager()
+ providers_manager._provider_dict = LazyDictWithCache()
providers_manager._provider_dict["apache-airflow-providers-apache-hive"] = ProviderInfo(
version="0.0.1",
data={
diff --git a/tests/api_connexion/endpoints/test_provider_endpoint.py b/tests/api_connexion/endpoints/test_provider_endpoint.py
index 621419114e..7c973a9bb4 100644
--- a/tests/api_connexion/endpoints/test_provider_endpoint.py
+++ b/tests/api_connexion/endpoints/test_provider_endpoint.py
@@ -69,7 +69,7 @@ def configured_app(minimal_app_for_api):
class TestBaseProviderEndpoint:
@pytest.fixture(autouse=True)
- def setup_attrs(self, configured_app) -> None:
+ def setup_attrs(self, configured_app, cleanup_providers_manager) -> None:
self.app = configured_app
self.client = self.app.test_client() # type:ignore
diff --git a/tests/cli/commands/test_info_command.py b/tests/cli/commands/test_info_command.py
index 9670f3de6a..36a544f241 100644
--- a/tests/cli/commands/test_info_command.py
+++ b/tests/cli/commands/test_info_command.py
@@ -183,7 +183,7 @@ class TestInfoCommandMockHttpx:
("database", "sql_alchemy_conn"): "postgresql+psycopg2://postgres:airflow@postgres/airflow",
}
)
- def test_show_info_anonymize_fileio(self, setup_parser):
+ def test_show_info_anonymize_fileio(self, setup_parser, cleanup_providers_manager):
with mock.patch("airflow.cli.commands.info_command.httpx.post") as post:
post.return_value = httpx.Response(
status_code=200,
diff --git a/tests/conftest.py b/tests/conftest.py
index 886d6a1be7..3f7e640884 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1120,6 +1120,18 @@ def close_all_sqlalchemy_sessions():
close_all_sessions()
+@pytest.fixture()
+def cleanup_providers_manager():
+ from airflow.providers_manager import ProvidersManager
+
+ ProvidersManager()._cleanup()
+ ProvidersManager().initialize_providers_configuration()
+ try:
+ yield
+ finally:
+ ProvidersManager()._cleanup()
+
+
# The code below is a modified version of capture-warning code from
# https://github.com/athinkingape/pytest-capture-warnings