diff --git a/tests/unit/plugins/openstack/context/murano/test_murano_environments.py b/tests/unit/plugins/openstack/context/murano/test_murano_environments.py index 8285c8c94d..40eed37f2c 100644 --- a/tests/unit/plugins/openstack/context/murano/test_murano_environments.py +++ b/tests/unit/plugins/openstack/context/murano/test_murano_environments.py @@ -63,27 +63,20 @@ class MuranoEnvironmentGeneratorTestCase(test.TestCase): } @mock.patch("%s.murano.utils.MuranoScenario._create_environment" % SCN) - def test_setup(self, mock_murano_scenario__create_environment): - mock_env = mock.MagicMock() - mock_murano_scenario__create_environment.return_value = mock_env - + def test_setup(self, mock_create_env): murano_ctx = murano_environments.EnvironmentGenerator( self._get_context()) murano_ctx.setup() self.assertEqual(2, len(murano_ctx.context["tenants"])) tenant_id = murano_ctx.context["users"][0]["tenant_id"] - self.assertEqual([mock_env], + self.assertEqual([mock_create_env.return_value], murano_ctx.context["tenants"][tenant_id][ "environments"]) @mock.patch("%s.murano.utils.MuranoScenario._create_environment" % SCN) @mock.patch("%s.resource_manager.cleanup" % CTX) - def test_cleanup(self, mock_cleanup, - mock_murano_scenario__create_environment): - mock_env = mock.Mock() - mock_murano_scenario__create_environment.return_value = mock_env - + def test_cleanup(self, mock_cleanup, mock_create_env): murano_ctx = murano_environments.EnvironmentGenerator( self._get_context()) murano_ctx.setup() diff --git a/tests/unit/test_mock.py b/tests/unit/test_mock.py index 15e83d247b..0514864e54 100644 --- a/tests/unit/test_mock.py +++ b/tests/unit/test_mock.py @@ -90,6 +90,12 @@ class FuncMockArgsDecoratorsChecker(ast.NodeVisitor): def test_foobar(self, mock_class_abc): # must match the python-styled class name + method name """ + + # NOTE(amaretskiy): Disable check if shortest variant is too long + # because long name is not convenient and could + # even be blocked by PEP8 + SHORTEST_VARIANT_LEN_LIMIT = 25 + def __init__(self): self.errors = [] self.globals_ = {} @@ -252,12 +258,15 @@ class FuncMockArgsDecoratorsChecker(ast.NodeVisitor): for arg, dec_vars in six.moves.zip_longest(mock_args, mock_decs): if not self.check_name(arg, dec_vars): if arg and dec_vars: - error_msgs.append( - ("Argument '%(arg)s' misnamed; should be either of " - "%(dec)s that is derived from the mock decorator " - "args.\n") % { - "arg": arg, "dec": dec_vars} - ) + sorted_by_len = sorted( + dec_vars.variants, key=lambda i: len(i), reverse=True) + shortest_name = sorted_by_len.pop() + if len(shortest_name) <= self.SHORTEST_VARIANT_LEN_LIMIT: + error_msgs.append( + ("Argument '%(arg)s' misnamed; should be either " + "of %(dec)s that is derived from the mock " + "decorator args.\n") % {"arg": arg, + "dec": dec_vars}) elif not arg: error_msgs.append( "Missing or malformed argument for %s decorator."