Skip to content

Commit

Permalink
Add a test that reproduces airflow#12785
Browse files Browse the repository at this point in the history
Added a test case to reproduce the issue reported in
apache#12785
  • Loading branch information
Rik Heijdens committed Dec 7, 2020
1 parent eed6576 commit 39a4e88
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/plugins/test_plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import importlib
import logging
import unittest
from unittest import mock
Expand Down Expand Up @@ -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)


class TestPluginsDirectorySource(unittest.TestCase):
def test_should_return_correct_path_name(self):
Expand Down

0 comments on commit 39a4e88

Please sign in to comment.