From 6e24c8f5b645df4dc61dc220386ec86cfb109b56 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 1 Apr 2022 11:14:42 -0400 Subject: [PATCH] run_tasks: Do not mask missing task dependencies While doing packaging work, I noticed that teuthology began claiming it couldn't find the 'tests' task. After some slightly painful debugging I realized the issue was that the task was trying to import pytest, which wasn't installed. The ModuleNotFoundError that was being raised was being confused with the exception that would be raised if the task couldn't be found at all. With this change, we see the root cause. Signed-off-by: Zack Cerza --- teuthology/run_tasks.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/teuthology/run_tasks.py b/teuthology/run_tasks.py index 602559f7fb..598947c807 100644 --- a/teuthology/run_tasks.py +++ b/teuthology/run_tasks.py @@ -1,3 +1,4 @@ +import importlib import jinja2 import logging import os @@ -60,6 +61,17 @@ def _import(from_package, module_name, task_name, fail_on_import_error=False): if fail_on_import_error: raise else: + if ( + importlib.util.find_spec(from_package) is not None and + importlib.util.find_spec(full_module_name) is not None + ): + # If we get here, it means we could _find_ both the module and + # the package that contains it, but still got an ImportError. + # Typically that means the module failed to import because it + # could not find one of its dependencies; if we don't raise + # here it will look like we just could't find the module, + # making the dependency issue difficult to discover. + raise return None return module -- 2.39.5