Fix bug #740 where plugin is not loaded.

This commit is contained in:
Tim 2021-01-18 15:44:43 +00:00
parent b4627896d3
commit e682f39fe6
No known key found for this signature in database
GPG Key ID: 3D454289AF831A6D
2 changed files with 26 additions and 5 deletions

View File

@ -147,11 +147,15 @@ class State(LogMixin, metaclass=Singleton):
:return: Have the preconditions been met.
:rtype: bool
"""
if self.modules[name].requires is None:
return self.modules[name].pass_preconditions
else:
mod = self.modules[name].requires
return self.modules[mod].pass_preconditions
try:
if self.modules[name].requires is None:
return self.modules[name].pass_preconditions
else:
mod = self.modules[name].requires
return self.modules[mod].pass_preconditions
except KeyError:
# Module is missing so therefore not found.
return False
def list_plugins(self):
"""

View File

@ -207,3 +207,20 @@ def test_check_preconditions_required_module(state):
# THEN: The correct result should be returned
assert result is False
def test_check_preconditions_missing_module(state):
"""
Test that the check_preconditions() method returns the correct attribute when the module is missing
"""
# GIVEN: A State with two modules
State().modules.update({
'test_pre2': MagicMock(requires='test_pre3', pass_preconditions=True),
'test_pre3': MagicMock(requires=None, pass_preconditions=False)
})
# WHEN: check_preconditions() is called
result = State().check_preconditions('test_pre1')
# THEN: The correct result should be returned
assert result is False