jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1005760?usp=email )
Change subject: [bugfix] use require_modules instead of has_module in proofreadpage_tests.py ......................................................................
[bugfix] use require_modules instead of has_module in proofreadpage_tests.py
has_module() does not find 'bs4' but 'beautifulsoup4'. Use aspects.require_modules decorator instead. Use it on setUpClass to skip all tests at once; decoration the class would skip every test method.
Use ModuleNotFoundError instead if ImportError in require_modules which is raised when a module cannot be found. This exception was introduced with Python 3.6
Change-Id: I76e17adb2476b02b17ee5e514889fe1b497a1588 --- M tests/aspects.py M tests/proofreadpage_tests.py 2 files changed, 21 insertions(+), 9 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py index 4ae285e..efd5616 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -290,7 +290,7 @@ for required_module in required_modules: try: __import__(required_module, globals(), locals(), [], 0) - except ImportError: + except ModuleNotFoundError: missing += [required_module] if not missing: return obj diff --git a/tests/proofreadpage_tests.py b/tests/proofreadpage_tests.py index 09a9677..0e2c525 100755 --- a/tests/proofreadpage_tests.py +++ b/tests/proofreadpage_tests.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """Tests for the proofreadpage module.""" # -# (C) Pywikibot team, 2015-2023 +# (C) Pywikibot team, 2015-2024 # # Distributed under the terms of the MIT license. # @@ -21,8 +21,6 @@ ProofreadPage, TagAttr, ) -from pywikibot.tools import has_module -from tests import unittest_print from tests.aspects import TestCase, require_modules from tests.basepage import ( BasePageLoadRevisionsCachingTestBase, @@ -439,13 +437,9 @@ """Run tests which needs bs4 beeing installed."""
@classmethod + @require_modules('bs4') def setUpClass(cls): """Check whether bs4 module is installed already.""" - if not has_module('bs4'): - unittest_print( - f'all tests ({__name__}.{cls.__name__})\n{cls.__doc__}.. ', - end='\n') - cls.skipTest(cls, 'bs4 not installed') super().setUpClass()
pywikibot-commits@lists.wikimedia.org