RikHeijdens commented on a change in pull request #12788:
URL: https://github.com/apache/airflow/pull/12788#discussion_r535540115



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -213,6 +214,34 @@ def 
test_entrypoint_plugin_errors_dont_raise_exceptions(self, caplog):
             assert "Failed to import plugin test-entrypoint" in received_logs
             assert ("test.plugins.test_plugins_manager", "my_fake_module not 
found") in import_errors.items()
 
+    def test_registering_plugin_macros(self):
+        """
+        Tests whether macros that originate from plugins are being registered 
correctly.
+        """
+        from airflow import macros
+        from airflow.plugins_manager import integrate_macros_plugins
+
+        def custom_macro():
+            return 'foo'
+
+        class MacroPlugin(AirflowPlugin):
+            name = 'macro_plugin'
+            macros = [custom_macro]
+
+        with mock_plugin_manager(plugins=[MacroPlugin()]):
+            # Ensure the macros for the plugin have been integrated.
+            integrate_macros_plugins()
+            # Test whether the modules have been created as expected.
+            plugin_macros = 
importlib.import_module(f"airflow.macros.{MacroPlugin.name}")
+            for macro in MacroPlugin.macros:
+                # Verify that the macros added by the plugin are being set 
correctly
+                # on the plugin's macro module.
+                assert hasattr(plugin_macros, macro.__name__)
+            # Verify that the symbol table in airflow.macros has been updated 
with an entry for
+            # this plugin, this is necessary in order to allow the plugin's 
macros to be used when
+            # rendering templates.
+            assert hasattr(macros, MacroPlugin.name)

Review comment:
       I considered doing this, but the `__doc__` comment on the 
`mock_plugin_manager` seems to suggest that the scope of that mock is limited 
to the `airflow.plugins` module.
   
   While that mock does in fact clear out the `macros_modules` variable in 
`airflow.plugins`, it does not actually attempt to reverse any (side) effects 
that are caused by invoking `integrate_macros_plugins()`. I did a bit of 
searching through the code base, and it doesn't really appear that there is any 
test coverage for this function beyond the test I've just added.
   
   Because I want to avoid scope creep for the `mock_plugin_manager` fixture, 
and this is the only test case that actually appears to have to deal with side 
effects cause by calling `integrate_macros_plugins()`, I'm a bit hesitant to 
make changes beyond what's being proposed here.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to