jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/512310 )

Change subject: [cleanup] Skip test classes as a whole
......................................................................

[cleanup] Skip test classes as a whole

- Rename IndexPageTestCase to BS4TestCase
- use setupClass in BS4TestCase to verify bs4 module is available;
  raise SkipTest if not to skip the test class as a whole instead of
  skipping each test method of the class. SkipTest exception is necessary
  because skipTest method does not work for Python 2 inside setUpClass
  class method.

- Derive all test classes from BS4TestCase which need bs4
  and remove require_modules decorator

Change-Id: Iad96aa8875a109dc79bee08e36e2ec01786342a4
---
M tests/proofreadpage_tests.py
1 file changed, 28 insertions(+), 20 deletions(-)

Approvals:
  Mpaa: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/proofreadpage_tests.py b/tests/proofreadpage_tests.py
index efa1518..195c7df 100644
--- a/tests/proofreadpage_tests.py
+++ b/tests/proofreadpage_tests.py
@@ -13,7 +13,9 @@

 from pywikibot.data import api
 from pywikibot.proofreadpage import IndexPage, ProofreadPage
+from pywikibot.tools import has_module

+from tests import unittest_print
 from tests.aspects import unittest, require_modules, TestCase
 from tests.basepage_tests import (
     BasePageMethodsTestBase,
@@ -320,8 +322,24 @@
         self.assertEqual(page.quality_level, 0)


-@require_modules('bs4')
-class TestPageOCR(TestCase):
+class BS4TestCase(TestCase):
+
+    """Run tests which needs bs4 beeing installed."""
+
+    @classmethod
+    def setUpClass(cls):
+        """Check whether bs4 module is installed already."""
+        if not has_module('bs4'):
+            unittest_print(
+                'all tests ({module}.{name})\n{doc} ... '
+                .format(module=__name__, doc=cls.__doc__, name=cls.__name__),
+                end='')
+            # skipTest cannot be used with Python 2 for setUpClass
+            raise unittest.SkipTest('bs4 not installed')
+        super(BS4TestCase, cls).setUpClass()
+
+
+class TestPageOCR(BS4TestCase):

     """Test page ocr functions."""

@@ -394,8 +412,7 @@
             self.assertEqual(text, ref_text)


-@require_modules('bs4')
-class TestProofreadPageIndexProperty(TestCase):
+class TestProofreadPageIndexProperty(BS4TestCase):

     """Test ProofreadPage index property."""

@@ -453,15 +470,7 @@
         self.assertEqual(page._index, (None, []))


-@require_modules('bs4')
-class IndexPageTestCase(TestCase):
-
-    """Run tests related to IndexPage ProofreadPage extension."""
-
-    pass
-
-
-class TestIndexPageInvalidSite(IndexPageTestCase):
+class TestIndexPageInvalidSite(BS4TestCase):

     """Test IndexPage class."""

@@ -476,7 +485,7 @@
                           IndexPage, self.site, 'title')


-class TestIndexPageValidSite(IndexPageTestCase):
+class TestIndexPageValidSite(BS4TestCase):

     """Test IndexPage class."""

@@ -521,8 +530,7 @@
         self.assertEqual(page.namespace(), source.namespace)


-@require_modules('bs4')
-class TestBasePageMethodsIndexPage(BasePageMethodsTestBase):
+class TestBasePageMethodsIndexPage(BS4TestCase, BasePageMethodsTestBase):

     """Test behavior of ProofreadPage methods inherited from BasePage."""

@@ -541,7 +549,7 @@
         self._test_return_datatypes()


-class TestLoadRevisionsCachingIndexPage(IndexPageTestCase,
+class TestLoadRevisionsCachingIndexPage(BS4TestCase,
                                         BasePageLoadRevisionsCachingTestBase):

     """Test site.loadrevisions() caching."""
@@ -561,7 +569,7 @@


 @unittest.skip('T193637 and T114318')
-class TestIndexPageMappings(IndexPageTestCase):
+class TestIndexPageMappings(BS4TestCase):

     """Test IndexPage class."""

@@ -725,7 +733,7 @@
         self.assertEqual(list(gen), [])


-class TestIndexPageMappingsRedlinks(IndexPageTestCase):
+class TestIndexPageMappingsRedlinks(BS4TestCase):

     """Test IndexPage mappings with redlinks."""

@@ -769,7 +777,7 @@
         self.assertEqual(list(gen), self.pages)


-class TestIndexPageHasValidContent(IndexPageTestCase):
+class TestIndexPageHasValidContent(BS4TestCase):

     """Unit tests for has_valid_content()."""


--
To view, visit https://gerrit.wikimedia.org/r/512310
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Iad96aa8875a109dc79bee08e36e2ec01786342a4
Gerrit-Change-Number: 512310
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: D3r1ck01 <[email protected]>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to