Skip to content

Commit

Permalink
Bugfix/caplog flaky test in extra operator link test (apache#44331)
Browse files Browse the repository at this point in the history
* Fix Flaky test that uses CapLog to test Serialization

* Fix Flaky test that uses CapLog to test Serialization
  • Loading branch information
jscheffl authored Nov 24, 2024
1 parent cf6cdca commit 3545cde
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tests/serialization/test_dag_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,10 +1067,13 @@ def test_extra_serialized_field_and_operator_links(
assert "https://www.google.com" == link

@pytest.mark.usefixtures("clear_all_logger_handlers")
def test_extra_operator_links_logs_error_for_non_registered_extra_links(self, caplog):
def test_extra_operator_links_logs_error_for_non_registered_extra_links(self):
"""
Assert OperatorLinks not registered via Plugins and if it is not an inbuilt Operator Link,
it can still deserialize the DAG (does not error) but just logs an error
it can still deserialize the DAG (does not error) but just logs an error.
We test NOT using caplog as this is flaky, we check that the task after deserialize
is missing the extra links.
"""

class TaskStateLink(BaseOperatorLink):
Expand All @@ -1094,13 +1097,8 @@ def execute(self, context: Context):

serialized_dag = SerializedDAG.to_dict(dag)

with caplog.at_level("ERROR", logger="airflow.serialization.serialized_objects"):
SerializedDAG.from_dict(serialized_dag)

expected_err_msg = (
"Operator Link class 'tests.serialization.test_dag_serialization.TaskStateLink' not registered"
)
assert expected_err_msg in caplog.text
sdag = SerializedDAG.from_dict(serialized_dag)
assert sdag.task_dict["blah"].operator_extra_links == []

class ClassWithCustomAttributes:
"""
Expand Down

0 comments on commit 3545cde

Please sign in to comment.