uranusjr commented on code in PR #57853:
URL: https://github.com/apache/airflow/pull/57853#discussion_r2517516288
##########
airflow-core/tests/unit/serialization/test_dag_serialization.py:
##########
@@ -113,31 +113,30 @@ def operator_defaults(overrides):
with operator_defaults({"retries": 2, "retry_delay": 200.0}):
# Test code with modified operator defaults
"""
+ import airflow.sdk.definitions._internal.abstractoperator as
abstract_op_module
from airflow.sdk.bases.operator import OPERATOR_DEFAULTS
+ from airflow.serialization.serialized_objects import SerializedBaseOperator
original_values = {}
- try:
- # Store original values and apply overrides
- for key, value in overrides.items():
- original_values[key] = OPERATOR_DEFAULTS.get(key)
- OPERATOR_DEFAULTS[key] = value
+ with pytest.MonkeyPatch.context() as monkeypatch:
Review Comment:
This can use the `monkeypatch` fixture instead, which automatically reverts
the patches when the function exits. That’d be cleaner IMO.
##########
airflow-core/tests/unit/serialization/test_dag_serialization.py:
##########
@@ -113,31 +113,30 @@ def operator_defaults(overrides):
with operator_defaults({"retries": 2, "retry_delay": 200.0}):
# Test code with modified operator defaults
"""
+ import airflow.sdk.definitions._internal.abstractoperator as
abstract_op_module
from airflow.sdk.bases.operator import OPERATOR_DEFAULTS
+ from airflow.serialization.serialized_objects import SerializedBaseOperator
original_values = {}
- try:
- # Store original values and apply overrides
- for key, value in overrides.items():
- original_values[key] = OPERATOR_DEFAULTS.get(key)
- OPERATOR_DEFAULTS[key] = value
+ with pytest.MonkeyPatch.context() as monkeypatch:
Review Comment:
It would require turning this thing into a fixture itself, but I think it’s
worthiwhile.
--
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]