kaxil commented on code in PR #62922:
URL: https://github.com/apache/airflow/pull/62922#discussion_r2963398586
##########
task-sdk/tests/task_sdk/definitions/conftest.py:
##########
@@ -47,3 +49,10 @@ def run(dag: DAG, task_id: str, map_index: int):
raise RuntimeError("Unable to find call to TaskState")
return run
+
+
+def make_xcom_arg(values: Any) -> XComArg:
+ op = BaseOperator(task_id="upstream")
+ xcom_arg = XComArg(op)
+ patch.object(xcom_arg, "resolve", return_value=values).start()
Review Comment:
Still unaddressed from previous review: `patch.object(...).start()` without
a matching `.stop()` leaks the mock for the rest of the test session. Each call
to `make_xcom_arg` patches a new `XComArg.resolve` but never restores the
original.
Either accept `monkeypatch` as a parameter (consistent with the test
refactoring done elsewhere in this PR):
```python
def make_xcom_arg(values: Any, monkeypatch) -> XComArg:
op = BaseOperator(task_id="upstream")
xcom_arg = XComArg(op)
monkeypatch.setattr(xcom_arg, "resolve", lambda *a, **kw: values)
return xcom_arg
```
Or call `.stop()` via a fixture finalizer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]