From d26b0bc19bf2666810c4ad0b14c03edf60c6ee3b Mon Sep 17 00:00:00 2001 From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com> Date: Thu, 20 Jan 2022 21:12:59 +0100 Subject: [PATCH 1/2] test_replaygain: fix complicated and incorrect exception handling This is an incorrect translation of a python 2 reraise to python 3. With python 3, however, we can just rely on exception chaining to get the traceback, so get rid of the complicated re-raising entirely, with the additional benefit that the exception from the tear-down is also shown. --- test/test_replaygain.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test/test_replaygain.py b/test/test_replaygain.py index b39a4e990..58b487fad 100644 --- a/test/test_replaygain.py +++ b/test/test_replaygain.py @@ -55,18 +55,8 @@ class ReplayGainCliTestBase(TestHelper): try: self.load_plugins('replaygain') except Exception: - import sys - # store exception info so an error in teardown does not swallow it - exc_info = sys.exc_info() - try: - self.teardown_beets() - self.unload_plugins() - except Exception: - # if load_plugins() failed then setup is incomplete and - # teardown operations may fail. In particular # {Item,Album} - # may not have the _original_types attribute in unload_plugins - pass - raise None.with_traceback(exc_info[2]) + self.teardown_beets() + self.unload_plugins() album = self.add_album_fixture(2) for item in album.items(): From c272696d9f6bc8426ebb961906d0deea5c841d9e Mon Sep 17 00:00:00 2001 From: wisp3rwind <17089248+wisp3rwind@users.noreply.github.com> Date: Thu, 20 Jan 2022 21:16:17 +0100 Subject: [PATCH 2/2] test_logging: fix incorrect exception handling Another incorrect py2 -> py3 translation. Since python 3 attached the traceback to the exception, this should preserve the traceback without needing to resort to sys.exc_info --- test/test_logging.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/test_logging.py b/test/test_logging.py index 8a9fd8742..79ff5cae2 100644 --- a/test/test_logging.py +++ b/test/test_logging.py @@ -175,7 +175,7 @@ class ConcurrentEventsTest(TestCase, helper.TestHelper): self.lock1 = threading.Lock() self.lock2 = threading.Lock() self.test_case = test_case - self.exc_info = None + self.exc = None self.t1_step = self.t2_step = 0 def log_all(self, name): @@ -190,9 +190,8 @@ class ConcurrentEventsTest(TestCase, helper.TestHelper): self.lock1.acquire() self.test_case.assertEqual(self._log.level, log.INFO) self.t1_step = 2 - except Exception: - import sys - self.exc_info = sys.exc_info() + except Exception as e: + self.exc = e def listener2(self): try: @@ -201,9 +200,8 @@ class ConcurrentEventsTest(TestCase, helper.TestHelper): self.lock2.acquire() self.test_case.assertEqual(self._log.level, log.DEBUG) self.t2_step = 2 - except Exception: - import sys - self.exc_info = sys.exc_info() + except Exception as e: + self.exc = e def setUp(self): self.setup_beets(disk=True) @@ -215,8 +213,8 @@ class ConcurrentEventsTest(TestCase, helper.TestHelper): dp = self.DummyPlugin(self) def check_dp_exc(): - if dp.exc_info: - raise None.with_traceback(dp.exc_info[2]) + if dp.exc: + raise dp.exc try: dp.lock1.acquire()