From 46f9f4248fb074365ce2ac808791f9faee9a7dfe Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Apr 16 2024 12:54:44 +0000
Subject: [PATCH 1/2] avoid test failure when running in console


---

diff --git a/tests/test_cli/test_download_task.py b/tests/test_cli/test_download_task.py
index b6138fa..6fb54ec 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 80bff41db5833ae53debe541577f97048cab8c0c Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Apr 16 2024 12:58:39 +0000
Subject: [PATCH 2/2] more mock.patch cleanup


---

diff --git a/tests/test_cli/test_get_options.py b/tests/test_cli/test_get_options.py
index 35fc26d..5a0dd52 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 72cd560..24fbc02 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 392f569..1bdf670 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 e3d486c..987483f 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 7eea290..f91ae4e 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 32f0ecf..59cb51d 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 fad921d..54ae918 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 14afc03..5050623 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 50778e4..66cb8ff 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 e9ae267..e152e66 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 e81c8b1..51de05c 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 6355877..898e315 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 457e179..f199723 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 15d09d6..d364fa3 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 688017a..15d5af8 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 51bcf2e..ba04035 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 c71e929..6949e51 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 ab469cc..2e7513b 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 d41f54e..92d226e 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'))

