Stop provider tests leaking AF2 global TI session (#73272)

This commit is contained in:
Amogh Desai authored and GitHub committed 2026-09-17 14:34:03 +02:00
1 parent 3362f56417
commit 25606f5f1c
2 files changed
+20 -9

No files matched your search

@@ -2147,6 +2147,26 @@ def reset_team_name_cache():
clear_team_name_cache()
@pytest.fixture(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
@@ -86,15 +86,6 @@ PY38 = sys.version_info >= (3, 8)
PY311 = sys.version_info >= (3, 11)
@pytest.fixture(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