Skip to content

Commit

Permalink
Correctly capture debug logs in plugin tests. (#14058)
Browse files Browse the repository at this point in the history
This fixes the test test_should_load_plugins_from_property, which is currently quarantined as a "Heisentest".

Current behavior:
The test currently fails because the records that it expects to find in the logger are not present.

Cause:
While the test sets the logger as "DEBUG", it doesn't specify which logger to update. Python loggers are namespaced (typically based on the current file's path), but this has to be defined explicitly. In the absence of a specified logger, any attempts to lookup will return the BaseLogger instance.

The test is therefore updating the log level for the base logger, but when the test runs, the plugins_manager.py file defines a namespaced logger log = logging.getLogger(__name__) used throughout the file. Since a different logger is used, the original log level, in this case INFO, is used. INFO is a higher level than DEBUG, so the calls to log.debug() get filtered out, and when the test looks for log records it finds an empty list.

Fix:
Just specify which logger to update when modifying the log level in the test.
  • Loading branch information
jhtimmins authored Feb 4, 2021
1 parent eb78a8b commit e80ad5a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/plugins/test_plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class TestPropertyHook(BaseHook):
with mock_plugin_manager(plugins=[AirflowTestPropertyPlugin()]):
from airflow import plugins_manager

caplog.set_level(logging.DEBUG)
caplog.set_level(logging.DEBUG, "airflow.plugins_manager")
plugins_manager.ensure_plugins_loaded()

assert 'AirflowTestPropertyPlugin' in str(plugins_manager.plugins)
Expand Down

0 comments on commit e80ad5a

Please sign in to comment.