@@ -61,9 +61,11 @@ def setup_test_cases(self, monkeypatch):
61
61
)
62
62
),
63
63
)
64
- with mock .patch ("airflow.models.baseoperator.BaseOperator.xcom_push" , return_value = None ) as m :
65
- self .mocked_xcom_push = m
66
- yield
64
+ # Mock task instance for xcom_push
65
+ mock_ti = mock .Mock ()
66
+ mock_ti .xcom_push = mock .Mock (return_value = None )
67
+ self .mock_ti = mock_ti
68
+ self .mock_context = {"task_instance" : mock_ti }
67
69
68
70
def test_operator_init_with_optional_args (self ):
69
71
jira_operator = JiraOperator (task_id = "jira_list_issue_types" , jira_method = "issue_types" )
@@ -80,11 +82,11 @@ def test_project_issue_count(self, mocked_jira_client):
80
82
jira_method_args = {"project" : "ABC" },
81
83
)
82
84
83
- op .execute ({})
85
+ op .execute (self . mock_context ) # type: ignore[arg-type]
84
86
85
87
assert mocked_jira_client .called
86
88
assert mocked_jira_client .return_value .get_project_issues_count .called
87
- self .mocked_xcom_push . assert_called_once_with (mock . ANY , key = "id" , value = None )
89
+ self .mock_ti . xcom_push . assert_called_once_with (key = "id" , value = None )
88
90
89
91
def test_issue_search (self , mocked_jira_client ):
90
92
jql_str = "issuekey=TEST-1226"
@@ -95,11 +97,11 @@ def test_issue_search(self, mocked_jira_client):
95
97
jira_method_args = {"jql" : jql_str , "limit" : "1" },
96
98
)
97
99
98
- op .execute ({})
100
+ op .execute (self . mock_context ) # type: ignore[arg-type]
99
101
100
102
assert mocked_jira_client .called
101
103
assert mocked_jira_client .return_value .jql_get_list_of_tickets .called
102
- self .mocked_xcom_push . assert_called_once_with (mock . ANY , key = "id" , value = "911539" )
104
+ self .mock_ti . xcom_push . assert_called_once_with (key = "id" , value = "911539" )
103
105
104
106
def test_update_issue (self , mocked_jira_client ):
105
107
mocked_jira_client .return_value .issue_add_comment .return_value = MINIMAL_TEST_TICKET
@@ -110,8 +112,8 @@ def test_update_issue(self, mocked_jira_client):
110
112
jira_method_args = {"issue_key" : MINIMAL_TEST_TICKET .get ("key" ), "comment" : "this is test comment" },
111
113
)
112
114
113
- op .execute ({})
115
+ op .execute (self . mock_context ) # type: ignore[arg-type]
114
116
115
117
assert mocked_jira_client .called
116
118
assert mocked_jira_client .return_value .issue_add_comment .called
117
- self .mocked_xcom_push . assert_called_once_with (mock . ANY , key = "id" , value = "911539" )
119
+ self .mock_ti . xcom_push . assert_called_once_with (key = "id" , value = "911539" )
0 commit comments