SameerMesiah97 commented on code in PR #74190:
URL: https://github.com/apache/airflow/pull/74190#discussion_r4178349446


##########
providers/openlineage/tests/unit/openlineage/extractors/test_manager.py:
##########
@@ -617,6 +620,68 @@ def 
test_get_hook_lineage_returns_none_when_nothing_collected(hook_lineage_colle
     mock_sql_fn.assert_not_called()
 
 
+@patch("airflow.providers.common.compat.lineage.hook.get_hook_lineage_collector",
 autospec=True)
+@patch(
+    
"airflow.providers.openlineage.extractors.manager._is_hook_lineage_collector_created",
+    autospec=True,
+    return_value=False,
+)
+def test_get_hook_lineage_does_not_create_collector(mock_created, 
mock_get_collector):
+    """Creating the collector only to read it back empty imports every 
provider's asset URI handlers."""
+    result = ExtractorManager().get_hook_lineage(
+        task_instance=MagicMock(spec=TaskInstance), 
task_instance_state=TaskInstanceState.SUCCESS
+    )
+
+    assert result is None
+    mock_get_collector.assert_not_called()
+
+
[email protected](not AIRFLOW_V_3_2_PLUS, reason="Airflow 3.2+ caches the 
collector getter")
+class TestIsHookLineageCollectorCreatedAirflow32:
+    def test_false_when_collector_never_created(self):
+        from airflow.sdk import lineage
+
+        lineage.get_hook_lineage_collector.cache_clear()
+
+        assert _is_hook_lineage_collector_created() is False

Review Comment:
   I think it is a bit risky to real process-wide via 
lineage.get_hook_lineage_collector.cache_clear(). Could interfere with other 
tests. How does the below look to you:
   
   ```
   def test_false_when_collector_never_created(self):
       with patch("airflow.sdk.lineage.get_hook_lineage_collector", 
autospec=True) as mock_getter:
           mock_getter.cache_info.return_value = MagicMock(spec=["currsize"], 
currsize=0)
   
           assert _is_hook_lineage_collector_created() is False
   ```



-- 
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]

Reply via email to