From 1a51320e866acaa110502a009cc78e86e13649ae Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Mon, 15 Apr 2024 12:41:51 -0400 Subject: [PATCH 1/2] avoid test failure when running in console --- tests/test_cli/test_download_task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli/test_download_task.py b/tests/test_cli/test_download_task.py index b6138faf..6fb54ec7 100644 --- a/tests/test_cli/test_download_task.py +++ b/tests/test_cli/test_download_task.py @@ -339,7 +339,7 @@ Default behavior without --all option downloads .rpm files only for build and bu self.download_file.assert_not_called() def test_handle_download_parent_not_finished(self): - args = [str(self.parent_task_id)] + args = [str(self.parent_task_id), '--nowait'] self.session.getTaskInfo.return_value = { 'id': self.parent_task_id, 'method': 'buildArch', From 48d78bd535fae51ddd4ca7582ca83542b1ca6784 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Mon, 15 Apr 2024 16:29:47 -0400 Subject: [PATCH 2/2] more mock.patch cleanup --- tests/test_cli/test_get_options.py | 1 + tests/test_cli/test_hostinfo.py | 1 + tests/test_cli/test_list_external_repos.py | 1 + tests/test_cli/test_list_hosts.py | 1 + tests/test_cli/test_list_tagged.py | 1 + tests/test_hub/test_get_build.py | 3 +++ tests/test_hub/test_get_build_targets.py | 3 +++ tests/test_hub/test_get_build_type.py | 3 +++ tests/test_hub/test_get_channel.py | 3 +++ tests/test_hub/test_get_group_members.py | 3 +++ tests/test_hub/test_get_image_build.py | 3 +++ tests/test_hub/test_get_maven_build.py | 3 +++ tests/test_hub/test_get_next_release.py | 3 +++ tests/test_hub/test_get_session_info.py | 3 +++ tests/test_hub/test_get_tag_external_repos.py | 3 +++ tests/test_hub/test_get_user.py | 3 +++ tests/test_hub/test_get_win_build.py | 3 +++ tests/test_lib/test_query_processor.py | 1 + tests/test_plugins/test_protonmsg.py | 2 ++ 19 files changed, 44 insertions(+) diff --git a/tests/test_cli/test_get_options.py b/tests/test_cli/test_get_options.py index 35fc26dc..5a0dd527 100644 --- a/tests/test_cli/test_get_options.py +++ b/tests/test_cli/test_get_options.py @@ -36,6 +36,7 @@ class TestGetOptions(unittest.TestCase): koji.BASEDIR = self.orig_basedir koji.pathinfo.topdir = self.orig_pathinfo_topdir cli.load_plugins = self.orig_load_plugins + mock.patch.stopall() def test_get_options(self): self.read_config.return_value = self.config_dict diff --git a/tests/test_cli/test_hostinfo.py b/tests/test_cli/test_hostinfo.py index 72cd5600..24fbc023 100644 --- a/tests/test_cli/test_hostinfo.py +++ b/tests/test_cli/test_hostinfo.py @@ -50,6 +50,7 @@ class TestHostinfo(utils.CliTestCase): else: os.environ['TZ'] = self.original_timezone time.tzset() + mock.patch.stopall() def test_hostinfo_without_option(self): self.session.getChannel.return_value = None diff --git a/tests/test_cli/test_list_external_repos.py b/tests/test_cli/test_list_external_repos.py index 392f569d..1bdf6706 100644 --- a/tests/test_cli/test_list_external_repos.py +++ b/tests/test_cli/test_list_external_repos.py @@ -42,6 +42,7 @@ class TestListExternalRepo(utils.CliTestCase): else: os.environ['TZ'] = self.original_timezone time.tzset() + mock.patch.stopall() def test_list_external_repos_with_args(self): arguments = ['arg'] diff --git a/tests/test_cli/test_list_hosts.py b/tests/test_cli/test_list_hosts.py index e3d486c5..987483fb 100644 --- a/tests/test_cli/test_list_hosts.py +++ b/tests/test_cli/test_list_hosts.py @@ -46,6 +46,7 @@ class TestListHosts(utils.CliTestCase): else: os.environ['TZ'] = self.original_timezone time.tzset() + mock.patch.stopall() def __vm(self, result): m = koji.VirtualCall('mcall_method', [], {}) diff --git a/tests/test_cli/test_list_tagged.py b/tests/test_cli/test_list_tagged.py index 7eea2902..f91ae4e2 100644 --- a/tests/test_cli/test_list_tagged.py +++ b/tests/test_cli/test_list_tagged.py @@ -85,6 +85,7 @@ class TestCliListTagged(utils.CliTestCase): else: os.environ['TZ'] = self.original_timezone time.tzset() + mock.patch.stopall() @mock.patch('sys.stdout', new_callable=six.StringIO) @mock.patch('koji.util.eventFromOpts', return_value={'id': 1000, diff --git a/tests/test_hub/test_get_build.py b/tests/test_hub/test_get_build.py index 32f0ecfa..59cb51da 100644 --- a/tests/test_hub/test_get_build.py +++ b/tests/test_hub/test_get_build.py @@ -12,6 +12,9 @@ class TestGetBuild(DBQueryTestCase): self.find_build_id = mock.patch('kojihub.kojihub.find_build_id').start() self.lookup_name = mock.patch('kojihub.kojihub.lookup_name').start() + def tearDown(self): + mock.patch.stopall() + def test_non_exist_build_string_with_strict(self): build = 'build-1-23' self.find_build_id.side_effect = koji.GenericError('No such build: %s' % build) diff --git a/tests/test_hub/test_get_build_targets.py b/tests/test_hub/test_get_build_targets.py index fad921d3..54ae918a 100644 --- a/tests/test_hub/test_get_build_targets.py +++ b/tests/test_hub/test_get_build_targets.py @@ -20,6 +20,9 @@ class TestGetBuildTargets(DBQueryTestCase): self.build_tag_id = 1 self.dest_tag_id = 2 + def tearDown(self): + mock.patch.stopall() + def test_get_build_targets_strings(self): self.name_or_id_clause.return_value = '(build_target.name = %(build_target_name)s)', \ {'build_target_name': 'build-target-url'} diff --git a/tests/test_hub/test_get_build_type.py b/tests/test_hub/test_get_build_type.py index 14afc035..50506237 100644 --- a/tests/test_hub/test_get_build_type.py +++ b/tests/test_hub/test_get_build_type.py @@ -14,6 +14,9 @@ class TestGetBuildType(DBQueryTestCase): self.get_win_build = mock.patch('kojihub.kojihub.get_win_build').start() self.get_image_build = mock.patch('kojihub.kojihub.get_image_build').start() + def tearDown(self): + mock.patch.stopall() + def test_no_build(self): self.get_build.return_value = None diff --git a/tests/test_hub/test_get_channel.py b/tests/test_hub/test_get_channel.py index 50778e4d..66cb8ff3 100644 --- a/tests/test_hub/test_get_channel.py +++ b/tests/test_hub/test_get_channel.py @@ -12,6 +12,9 @@ class TestGetChannel(DBQueryTestCase): self.context = mock.patch('kojihub.kojihub.context').start() self.exports = kojihub.RootExports() + def tearDown(self): + mock.patch.stopall() + def test_wrong_type_channelInfo(self): # dict channel_info = {'channel': 'val'} diff --git a/tests/test_hub/test_get_group_members.py b/tests/test_hub/test_get_group_members.py index e9ae2673..e152e66a 100644 --- a/tests/test_hub/test_get_group_members.py +++ b/tests/test_hub/test_get_group_members.py @@ -12,6 +12,9 @@ class TestGetGroupMembers(DBQueryTestCase): self.get_user = mock.patch('kojihub.kojihub.get_user').start() self.exports = kojihub.RootExports() + def tearDown(self): + mock.patch.stopall() + def test_non_exist_group(self): group = 'test-group' self.get_user.return_value = [] diff --git a/tests/test_hub/test_get_image_build.py b/tests/test_hub/test_get_image_build.py index e81c8b13..51de05c8 100644 --- a/tests/test_hub/test_get_image_build.py +++ b/tests/test_hub/test_get_image_build.py @@ -11,6 +11,9 @@ class TestGetImageBuild(DBQueryTestCase): self.maxDiff = None self.find_build_id = mock.patch('kojihub.kojihub.find_build_id').start() + def tearDown(self): + mock.patch.stopall() + def test_build_id_not_found(self): self.find_build_id.return_value = None result = kojihub.get_image_build('test-build.1-23.1') diff --git a/tests/test_hub/test_get_maven_build.py b/tests/test_hub/test_get_maven_build.py index 63558771..898e3152 100644 --- a/tests/test_hub/test_get_maven_build.py +++ b/tests/test_hub/test_get_maven_build.py @@ -11,6 +11,9 @@ class TestGetMavenBuild(DBQueryTestCase): self.maxDiff = None self.find_build_id = mock.patch('kojihub.kojihub.find_build_id').start() + def tearDown(self): + mock.patch.stopall() + def test_build_id_not_found(self): self.find_build_id.return_value = None result = kojihub.get_maven_build('test-build.1-23.1') diff --git a/tests/test_hub/test_get_next_release.py b/tests/test_hub/test_get_next_release.py index 457e1796..f199723c 100644 --- a/tests/test_hub/test_get_next_release.py +++ b/tests/test_hub/test_get_next_release.py @@ -12,6 +12,9 @@ class TestGetNextRelease(DBQueryTestCase): self.get_build = mock.patch('kojihub.kojihub.get_build').start() self.binfo = {'name': 'name', 'version': 'version'} + def tearDown(self): + mock.patch.stopall() + def test_get_next_release_new(self): # no previous build self.qp_execute_one_return_value = None diff --git a/tests/test_hub/test_get_session_info.py b/tests/test_hub/test_get_session_info.py index 15d09d67..d364fa3c 100644 --- a/tests/test_hub/test_get_session_info.py +++ b/tests/test_hub/test_get_session_info.py @@ -14,6 +14,9 @@ class TestGetSessionInfo(DBQueryTestCase): self.userinfo = {'id': 123, 'name': 'testuser'} self.exports.getLoggedInUser = mock.MagicMock() + def tearDown(self): + mock.patch.stopall() + def test_get_session_info_not_logged(self): self.context.session.logged_in = False result = self.exports.getSessionInfo() diff --git a/tests/test_hub/test_get_tag_external_repos.py b/tests/test_hub/test_get_tag_external_repos.py index 688017aa..15d5af85 100644 --- a/tests/test_hub/test_get_tag_external_repos.py +++ b/tests/test_hub/test_get_tag_external_repos.py @@ -19,6 +19,9 @@ class TestGetTagExternalRepos(DBQueryTestCase): self.build_tag_info = {'id': 111, 'name': self.build_tag} self.repo_info = {'id': 123, 'name': self.repo} + def tearDown(self): + mock.patch.stopall() + def test_valid(self): self.get_tag.return_value = self.build_tag_info self.get_external_repo.return_value = self.repo_info diff --git a/tests/test_hub/test_get_user.py b/tests/test_hub/test_get_user.py index 51bcf2e0..ba040356 100644 --- a/tests/test_hub/test_get_user.py +++ b/tests/test_hub/test_get_user.py @@ -15,6 +15,9 @@ class TestGetUser(DBQueryTestCase): self.list_user_krb_principals = mock.patch( 'kojihub.kojihub.list_user_krb_principals').start() + def tearDown(self): + mock.patch.stopall() + def test_wrong_format_user_info(self): userinfo = ['test-user'] with self.assertRaises(koji.GenericError) as cm: diff --git a/tests/test_hub/test_get_win_build.py b/tests/test_hub/test_get_win_build.py index c71e929e..6949e51f 100644 --- a/tests/test_hub/test_get_win_build.py +++ b/tests/test_hub/test_get_win_build.py @@ -11,6 +11,9 @@ class TestGetWinBuild(DBQueryTestCase): self.maxDiff = None self.find_build_id = mock.patch('kojihub.kojihub.find_build_id').start() + def tearDown(self): + mock.patch.stopall() + def test_build_id_not_found(self): self.find_build_id.return_value = None result = kojihub.get_win_build('test-build.1-23.1') diff --git a/tests/test_lib/test_query_processor.py b/tests/test_lib/test_query_processor.py index ab469ccb..2e7513b9 100644 --- a/tests/test_lib/test_query_processor.py +++ b/tests/test_lib/test_query_processor.py @@ -33,6 +33,7 @@ class TestQueryProcessor(unittest.TestCase): def tearDown(self): kojihub.QueryProcessor.iterchunksize = self.original_chunksize + mock.patch.stopall() def test_basic_instantiation(self): kojihub.QueryProcessor() # No exception! diff --git a/tests/test_plugins/test_protonmsg.py b/tests/test_plugins/test_protonmsg.py index d41f54ed..92d226e4 100644 --- a/tests/test_plugins/test_protonmsg.py +++ b/tests/test_plugins/test_protonmsg.py @@ -42,6 +42,8 @@ extra_limit = 2048 if hasattr(context, 'protonmsg_msgs'): del context.protonmsg_msgs del self.conf + mock.patch.stopall() + def assertMsg(self, topic, body=None, **kws): self.assertTrue(hasattr(context, 'protonmsg_msgs'))