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 25606f5f1cf Stop provider tests leaking AF2 global TI session (#73272)
25606f5f1cf is described below

commit 25606f5f1cf1dfce5f884d589eec63a328f7e2b4
Author: Amogh Desai <[email protected]>
AuthorDate: Thu Sep 17 18:04:03 2026 +0530

    Stop provider tests leaking AF2 global TI session (#73272)
---
 devel-common/src/tests_common/pytest_plugin.py       | 20 ++++++++++++++++++++
 .../tests/unit/standard/decorators/test_python.py    |  9 ---------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/devel-common/src/tests_common/pytest_plugin.py 
b/devel-common/src/tests_common/pytest_plugin.py
index e2d9913205f..529b4fabc95 100644
--- a/devel-common/src/tests_common/pytest_plugin.py
+++ b/devel-common/src/tests_common/pytest_plugin.py
@@ -2147,6 +2147,26 @@ def reset_team_name_cache():
         clear_team_name_cache()
 
 
[email protected](autouse=True)
+def clear_current_task_instance_session():
+    """Reset the process global taskinstance session between tests.
+
+    Reaching it outside a task run leaves it set, and every later ``ti.run()`` 
in the process
+    then raises "Session already set for this task". No-op on Airflow 3.
+    """
+    try:
+        import airflow.utils.task_instance_session as task_instance_session
+    except ModuleNotFoundError:
+        yield
+        return
+
+    task_instance_session.__current_task_instance_session = None
+    try:
+        yield
+    finally:
+        task_instance_session.__current_task_instance_session = None
+
+
 @pytest.fixture(autouse=True)
 def refuse_to_run_test_from_wrongly_named_files(request: 
pytest.FixtureRequest):
     filepath = request.node.path
diff --git a/providers/standard/tests/unit/standard/decorators/test_python.py 
b/providers/standard/tests/unit/standard/decorators/test_python.py
index ff2cc706e5e..fb972a652d4 100644
--- a/providers/standard/tests/unit/standard/decorators/test_python.py
+++ b/providers/standard/tests/unit/standard/decorators/test_python.py
@@ -86,15 +86,6 @@ PY38 = sys.version_info >= (3, 8)
 PY311 = sys.version_info >= (3, 11)
 
 
[email protected](autouse=True)
-def clear_current_task_session():
-    try:
-        import airflow.utils.task_instance_session
-    except ModuleNotFoundError:
-        return
-    airflow.utils.task_instance_session.__current_task_instance_session = None
-
-
 class TestAirflowTaskDecorator(BasePythonTest):
     default_date = DEFAULT_DATE
 

Reply via email to