diff --git a/st2client/tests/unit/test_commands.py b/st2client/tests/unit/test_commands.py index b5814ebf54..cae04c2e27 100644 --- a/st2client/tests/unit/test_commands.py +++ b/st2client/tests/unit/test_commands.py @@ -517,7 +517,6 @@ def test_help_command_line_arg_works_for_supported_commands(self): # optional arguments covers both formats. assert isinstance(re.search("(optional arguments:|options:)", stdout), re.Match) is True - # Verify that the actual help usage string was triggered and not the invalid # "too few arguments" which would indicate command doesn't actually correctly handle # --help flag diff --git a/st2common/st2common/expressions/functions/version.py b/st2common/st2common/expressions/functions/version.py index bf61c32e80..796d9289f3 100644 --- a/st2common/st2common/expressions/functions/version.py +++ b/st2common/st2common/expressions/functions/version.py @@ -60,4 +60,5 @@ def version_bump_patch(value): def version_strip_patch(value): - return "{major}.{minor}".format(**semver.Version.parse(value)) + sv = semver.Version.parse(value) + return f"{sv.major}.{sv.minor}" diff --git a/st2common/tests/unit/test_greenpooldispatch.py b/st2common/tests/unit/test_greenpooldispatch.py index 4208c348b2..f77ae2937e 100644 --- a/st2common/tests/unit/test_greenpooldispatch.py +++ b/st2common/tests/unit/test_greenpooldispatch.py @@ -36,7 +36,7 @@ def test_dispatch_simple(self): call_args_list = [ (args[0][0], args[0][1]) for args in mock_handler.call_args_list ] - self.assertItemsEqual(expected, call_args_list) + assert expected == call_args_list def test_dispatch_starved(self): dispatcher = BufferedDispatcher( @@ -55,4 +55,4 @@ def test_dispatch_starved(self): call_args_list = [ (args[0][0], args[0][1]) for args in mock_handler.call_args_list ] - self.assertItemsEqual(expected, call_args_list) + assert expected == call_args_list diff --git a/st2common/tests/unit/test_model_utils_profiling.py b/st2common/tests/unit/test_model_utils_profiling.py index db37039c80..bbdeee8c22 100644 --- a/st2common/tests/unit/test_model_utils_profiling.py +++ b/st2common/tests/unit/test_model_utils_profiling.py @@ -37,7 +37,7 @@ def test_logging_profiling_is_disabled(self, mock_log): result = log_query_and_profile_data_for_queryset(queryset=queryset) self.assertEqual(queryset, result) call_args_list = mock_log.debug.call_args_list - self.assertItemsEqual(call_args_list, []) + assert call_args_list == [] @mock.patch("st2common.models.utils.profiling.LOG") def test_logging_profiling_is_enabled(self, mock_log): diff --git a/st2common/tests/unit/test_util_file_system.py b/st2common/tests/unit/test_util_file_system.py index 0dceb142a5..fa579329ae 100644 --- a/st2common/tests/unit/test_util_file_system.py +++ b/st2common/tests/unit/test_util_file_system.py @@ -39,8 +39,11 @@ def test_get_file_list(self): "meta/concurrency.yaml", "meta/__init__.py", ] - result = get_file_list(directory=directory, exclude_patterns=["*.pyc"]) - self.assertItemsEqual(expected, result) + result = get_file_list(directory=directory, exclude_patterns=["*.pyc", "__pycache__"]) + # directory listings are sorted because the item order must be exact for assert + # to validate equivalence. Directory item order doesn't matter in general and may + # even change on different platforms or locales. + assert sorted(expected) == sorted(result) # Custom exclude pattern expected = [ @@ -52,4 +55,7 @@ def test_get_file_list(self): result = get_file_list( directory=directory, exclude_patterns=["*.pyc", "*.yaml", "*BUILD"] ) - self.assertItemsEqual(expected, result) + # directory listings are sorted because the item order must be exact for assert + # to validate equivalence. Directory item order doesn't matter in general and may + # even change on different platforms or locales. + assert sorted(expected) == sorted(result) diff --git a/st2reactor/tests/unit/test_timer.py b/st2reactor/tests/unit/test_timer.py index f4311d18d8..9ec00be5ec 100644 --- a/st2reactor/tests/unit/test_timer.py +++ b/st2reactor/tests/unit/test_timer.py @@ -31,8 +31,9 @@ def test_trigger_types_are_registered_on_start(self): timer = St2Timer() timer._scheduler = mock.Mock() - # Verify there are no TriggerType in the db when we start - self.assertItemsEqual(TriggerType.get_all(), []) + # Verify there are no TriggerType objects in the db when we start + # and cast Mongo QuerySet iterator cast to list for evaluation. + assert list(TriggerType.get_all()) == [] timer.start() @@ -55,8 +56,8 @@ def test_existing_rules_are_loaded_on_start(self): timer._trigger_watcher.run = mock.Mock() # Verify there are no Trigger and TriggerType in the db wh:w - self.assertItemsEqual(Trigger.get_all(), []) - self.assertItemsEqual(TriggerType.get_all(), []) + assert list(Trigger.get_all()) == [] + assert list(TriggerType.get_all()) == [] # Add a dummy timer Trigger object type_ = list(TIMER_TRIGGER_TYPES.keys())[0]