John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/154242

Change subject: Order of tests within test suite
......................................................................

Order of tests within test suite

Allow the order of tests to be specified for both Python 2.6 and 2.7
Disable the ui and weblib tests in the test loader.

Change-Id: Ic0e18457888b428222a9dcbefcec9e1740b573aa
---
M tests/__init__.py
M tests/utils.py
M tests/weblib_tests.py
3 files changed, 77 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/42/154242/1

diff --git a/tests/__init__.py b/tests/__init__.py
index 919064a..ee426b1 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -10,7 +10,7 @@
 import sys
 
 __all__ = ['httplib2', 'OrderedDict', '_cache_dir', 'TestRequest',
-           'patch_request', 'unpatch_request']
+           'patch_request', 'unpatch_request', 'unit_test_module_list']
 
 # Verify that the unit tests have a base working environment:
 # - httplib2 is mandatory
@@ -36,11 +36,80 @@
                 "Python 2.6")
         sys.exit(1)
 
+try:
+    import unittest2 as unittest
+except ImportError:
+    import unittest
+
 import pywikibot.data.api
 from pywikibot.data.api import Request as _original_Request
 from pywikibot.data.api import CachedRequest
 
-_cache_dir = os.path.join(os.path.split(__file__)[0], 'apicache')
+_tests_dir = os.path.split(__file__)[0]
+_cache_dir = os.path.join(_tests_dir, 'apicache')
+
+ordered_test_modules = [
+    'date',
+    'ipregex',
+    'xmlreader',
+    'textlib',
+    'http',
+    'namespace',
+    'dry_api',
+    'dry_site',
+    'api',
+    'site',
+    'page',
+    'file',
+    'timestripper',
+    'pagegenerators',
+    'wikidataquery',
+    'weblib',
+    'pwb',
+    'i18n',
+    'ui',
+    'script',
+]
+
+disabled_test_modules = [
+    'ui',
+]
+
+if os.environ.get('TRAVIS', 'false') == 'true':
+    disabled_test_modules.append('weblib')
+
+
+def unit_test_module_list(tests_path=_tests_dir):
+    """List tests which are to be executed."""
+    # Raising SkipTest during load_tests will
+    # cause the loader to fallback to its own
+    # discover() ordering of unit tests.
+    for name in disabled_test_modules:
+        print('Test module %s disabled' % name)
+
+    dir_list = os.listdir(tests_path)
+    all_test_list = [name[0:-9] for name in dir_list  # strip '_tests.py'
+                     if name.endswith('_tests.py')
+                     and not name.startswith('_')]   # skip __init__.py and _*
+
+    other_test_modules = [name
+                          for name in all_test_list  # strip _tests.py
+                          if name not in ordered_test_modules]
+
+    test_list = ['tests.' + name + '_tests'
+                 for name in ordered_test_modules + other_test_modules
+                 if name not in disabled_test_modules]
+
+    return test_list
+
+
+def load_tests(loader, tests, pattern):
+    tests = unittest.loader.defaultTestLoader.loadTestsFromNames(
+        unit_test_module_list(_tests_dir))
+    suite = unittest.TestSuite()
+    suite.addTests(tests)
+    return suite
+
 
 CachedRequest._get_cache_dir = staticmethod(
     lambda *args: CachedRequest._make_dir(_cache_dir))
diff --git a/tests/utils.py b/tests/utils.py
index f767538..89ddef4 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -22,6 +22,7 @@
     import unittest
 
 import pywikibot
+from tests import patch_request, unpatch_request, unit_test_module_list
 
 # Number of seconds each test may consume before a note is added after the 
test.
 test_duration_warning_interval = 10
@@ -32,9 +33,11 @@
     # matching the pattern `*tests.py`. This gets used by `setup.py test` when
     # running on Python 2.6 to use the unittest2 test runner instead of the
     # unittest one.
-    return unittest.loader.defaultTestLoader.discover("tests", "*tests.py")
-
-from tests import patch_request, unpatch_request
+    tests = unittest.loader.defaultTestLoader.loadTestsFromNames(
+        unit_test_module_list())
+    suite = unittest.TestSuite()
+    suite.addTests(tests)
+    return suite
 
 
 class BaseTestCase(unittest.TestCase):
diff --git a/tests/weblib_tests.py b/tests/weblib_tests.py
index bbac6fe..7afcd01 100644
--- a/tests/weblib_tests.py
+++ b/tests/weblib_tests.py
@@ -6,7 +6,6 @@
 #
 __version__ = '$Id$'
 
-import os
 import sys
 if sys.version_info[0] == 2:
     from urlparse import urlparse
@@ -20,11 +19,6 @@
 class TestArchiveSites(NoSiteTestCase):
 
     net = True
-
-    @classmethod
-    def setUpClass(cls):
-        if os.environ.get('TRAVIS', 'false') == 'true':
-            raise unittest.SkipTest('Weblib tests are disabled on Travis-CI')
 
     def testInternetArchiveNewest(self):
         archivedversion = weblib.getInternetArchiveURL('https://google.com')

-- 
To view, visit https://gerrit.wikimedia.org/r/154242
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic0e18457888b428222a9dcbefcec9e1740b573aa
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to