Skip to content

Commit

Permalink
Add cleanup logic to test_registering_plugin_macros
Browse files Browse the repository at this point in the history
This test-case has side-effects in the sense that the symbol table of
the airflow.macros module is altered when integrate_macros_plugins() is
invoked. This commit adds a finalizer to the test case that ensures that
that module is being reloaded completely in order to prevent impact on
other tests.
  • Loading branch information
Rik Heijdens committed Dec 4, 2020
1 parent 069d1af commit 6ce365f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/plugins/test_plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# under the License.
import importlib
import logging
import sys
import unittest
from unittest import mock

Expand Down Expand Up @@ -214,13 +215,24 @@ 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):
def test_registering_plugin_macros(self, request):
"""
Tests whether macros that originate from plugins are being registered correctly.
"""
from airflow import macros
from airflow.plugins_manager import integrate_macros_plugins

def cleanup_macros():
"""Reloads the airflow.macros module such that the symbol table is reset after the test."""
# We're explicitly deleting the module from sys.modules and importing it again
# using import_module() as opposed to using importlib.reload() because the latter
# does not undo the changes to the airflow.macros module that are being caused by
# invoking integrate_macros_plugins()
del sys.modules['airflow.macros']
importlib.import_module('airflow.macros')

request.addfinalizer(cleanup_macros)

def custom_macro():
return 'foo'

Expand Down

0 comments on commit 6ce365f

Please sign in to comment.