diff --git a/haruhi_dl/playwright.py b/haruhi_dl/playwright.py index 957bdfe74..36c341b11 100644 --- a/haruhi_dl/playwright.py +++ b/haruhi_dl/playwright.py @@ -22,7 +22,8 @@ class PlaywrightHelper(): cls._real_import_pw() except ImportError as err: if fatal is True: - raise ExtractorError('Playwright could not be imported: %s' % err.msg, expected=True) + raise ExtractorError('Playwright could not be imported: %s' % err.msg if 'msg' in err else '[no err.msg]', + expected=True) @classmethod def _version(cls): diff --git a/test/test_playwright.py b/test/test_playwright.py index 76d390c22..d4993ebba 100644 --- a/test/test_playwright.py +++ b/test/test_playwright.py @@ -8,6 +8,7 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from haruhi_dl.compat import compat_str +from haruhi_dl.utils import ExtractorError from haruhi_dl.playwright import PlaywrightHelper @@ -23,13 +24,17 @@ class TestPlaywright(unittest.TestCase): helper._import_pw(fatal=True) self.assertIsNotNone(helper._pw) self.assertIsInstance(helper._pw_version, compat_str) - except ImportError: + except ExtractorError: self.assertIsNone(helper._pw) self.assertIsNone(helper._pw_version) def test_checking_version(self): - version = PlaywrightHelper._version() - self.assertIsInstance(version, (compat_str, None)) + helper = PlaywrightHelper + version = helper._version() + if helper._pw: + self.assertIsInstance(version, compat_str) + else: + self.assertIsNone(version) if __name__ == '__main__':