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 <zack@redhat.com>
+import importlib
import jinja2
import logging
import os
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