This is an automated email from the ASF dual-hosted git repository.
dstandish 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 4f706d87fc Fix test side effects from TracebackSession (#38885)
4f706d87fc is described below
commit 4f706d87fc83683e9bb958674626920f2cd41a14
Author: Daniel Standish <[email protected]>
AuthorDate: Tue Apr 9 16:26:03 2024 -0700
Fix test side effects from TracebackSession (#38885)
---
Co-authored-by: Andrey Anshin <[email protected]>
---
tests/core/test_settings.py | 35 +++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/tests/core/test_settings.py b/tests/core/test_settings.py
index abaf4a907b..5eac456103 100644
--- a/tests/core/test_settings.py
+++ b/tests/core/test_settings.py
@@ -28,7 +28,7 @@ import pytest
from airflow.api_internal.internal_api_call import InternalApiConfig
from airflow.exceptions import AirflowClusterPolicyViolation,
AirflowConfigException
-from airflow.settings import _ENABLE_AIP_44, TracebackSession, configure_orm
+from airflow.settings import _ENABLE_AIP_44, TracebackSession
from airflow.utils.session import create_session
from tests.test_utils.config import conf_vars
@@ -65,6 +65,16 @@ def task_must_have_owners(task: BaseOperator):
"""
[email protected]
+def clear_internal_api():
+ try:
+ yield
+ finally:
+ InternalApiConfig._initialized = False
+ InternalApiConfig._use_internal_api = None
+ InternalApiConfig._internal_api_endpoint = None
+
+
class SettingsContext:
def __init__(self, content: str, module_name: str):
self.content = content
@@ -276,27 +286,22 @@ class TestEngineArgs:
("core", "internal_api_url"): "http://localhost:8888",
}
)
-def test_get_traceback_session_if_aip_44_enabled():
+def test_get_traceback_session_if_aip_44_enabled(clear_internal_api):
# ensure we take the database_access_isolation config
InternalApiConfig._init_values()
assert InternalApiConfig.get_use_internal_api() is True
- # ensure that the Session object is TracebackSession
- configure_orm()
-
- from airflow.settings import Session
-
- assert Session == TracebackSession
-
- # no error to create
with create_session() as session:
assert isinstance(session, TracebackSession)
+ # no error just to create the "session"
+ # but below, when we try to use, it will raise
+
with pytest.raises(
RuntimeError,
match="TracebackSession object was used but internal API is
enabled.",
):
- session.hi()
+ session.execute()
@pytest.mark.skipif(not _ENABLE_AIP_44, reason="AIP-44 is disabled")
@@ -307,21 +312,15 @@ def test_get_traceback_session_if_aip_44_enabled():
}
)
@patch("airflow.utils.session.TracebackSession.__new__")
-def test_create_session_ctx_mgr_no_call_methods(mock_new):
+def test_create_session_ctx_mgr_no_call_methods(mock_new, clear_internal_api):
m = MagicMock()
mock_new.return_value = m
# ensure we take the database_access_isolation config
InternalApiConfig._init_values()
assert InternalApiConfig.get_use_internal_api() is True
- # ensure that the Session object is TracebackSession
- configure_orm()
-
- # no error to create
with create_session() as session:
assert isinstance(session, MagicMock)
assert session == m
method_calls = [x[0] for x in m.method_calls]
assert method_calls == [] # commit and close not called when using
internal API
-
- # assert mock_session_obj.call_args_list == []