jenkins-bot has submitted this change and it was merged.
Change subject: test decorator allowed_failure
......................................................................
test decorator allowed_failure
Test runners each have different interpretations of what should be
the result of an @expectedFailure test if it succeeds. Some
consider it to be a pass; others a failure.
This new decorator runs the test and, if it is a failure, reports the
failure and considers it a skipped test.
Change-Id: Ia87dda2780a9fe4130b2820298f07f983d5db80b
---
M tests/api_tests.py
M tests/http_tests.py
M tests/site_tests.py
M tests/utils.py
4 files changed, 48 insertions(+), 13 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 9746229..bf43d3a 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -19,6 +19,7 @@
DefaultSiteTestCase,
DefaultDrySiteTestCase,
)
+from tests.utils import allowed_failure
class TestApiFunctions(DefaultSiteTestCase):
@@ -395,7 +396,7 @@
count += 1
self.assertEqual(len(links), count)
- @unittest.expectedFailure
+ @allowed_failure
def test_many_continuations_limited(self):
mainpage = self.get_mainpage()
links = list(self.site.pagelinks(mainpage, total=30))
@@ -419,7 +420,7 @@
self.assertEqual(len(links), count)
# FIXME: AssertionError: 30 != 6150
- @unittest.expectedFailure
+ @allowed_failure
def test_two_continuations_limited(self):
# FIXME: test fails
mainpage = self.get_mainpage()
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 0263d62..55698a5 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -13,7 +13,7 @@
from pywikibot.comms import http, threadedhttp
from pywikibot import config2 as config
from tests.aspects import unittest, TestCase
-from tests.utils import expectedFailureIf
+from tests.utils import expected_failure_if
if sys.version_info[0] > 2:
import queue as Queue
@@ -66,7 +66,7 @@
site=None,
uri='https://www.omegawiki.org/')
- @expectedFailureIf(sys.version_info[0] > 2) # bug 72236
+ @expected_failure_if(sys.version_info[0] > 2) # bug 72236
def test_https_ignore_cert_error(self):
"""Test http request function ignoring ssl bad certificate."""
# As the connection is cached, the above test will cause
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 5d7a964..4b56794 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -19,7 +19,6 @@
from pywikibot.tools import MediaWikiVersion as LV
from pywikibot.data import api
-from tests.utils import expectedFailureIf
from tests.aspects import (
unittest, TestCase,
DefaultSiteTestCase,
@@ -27,6 +26,7 @@
WikidataTestCase,
DefaultWikidataClientTestCase,
)
+from tests.utils import allowed_failure, allowed_failure_if
if sys.version_info[0] > 2:
basestring = (str, )
@@ -678,7 +678,7 @@
self.assertIsInstance(using, pywikibot.Page)
self.assertIn(imagepage, list(using.imagelinks()))
- @expectedFailureIf(os.environ.get('TRAVIS', 'false') == 'true')
+ @allowed_failure_if(os.environ.get('TRAVIS', 'false') == 'true')
def test_image_usage_in_redirects(self):
"""Test the site.imageusage() method on redirects only."""
mysite = self.get_site()
@@ -1772,7 +1772,7 @@
if count > 5:
break
- @unittest.expectedFailure
+ @allowed_failure
def test_preload_langlinks_normal(self):
"""Test preloading continuation works."""
# FIXME: test fails
@@ -1792,7 +1792,7 @@
if count >= 6:
break
- @unittest.expectedFailure
+ @allowed_failure
def test_preload_langlinks_count(self):
"""Test preloading continuation works."""
# FIXME: test fails
@@ -1834,7 +1834,7 @@
self.assertEqual(len(links), count)
- @unittest.expectedFailure
+ @allowed_failure
def test_preload_templates(self):
"""Test preloading templates works."""
mysite = self.get_site()
@@ -1854,7 +1854,7 @@
if count >= 6:
break
- @unittest.expectedFailure
+ @allowed_failure
def test_preload_templates_and_langlinks(self):
"""Test preloading templates and langlinks works."""
mysite = self.get_site()
diff --git a/tests/utils.py b/tests/utils.py
index c932e59..afb68eb 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -8,6 +8,7 @@
from __future__ import print_function
__version__ = '$Id$'
#
+
import pywikibot
from pywikibot.tools import SelfCallDict
from pywikibot.site import Namespace
@@ -24,15 +25,48 @@
PywikibotTestCase = aspects.TestCase
-def expectedFailureIf(expect):
+def expected_failure_if(expect):
"""
- Unit test decorator to expect/allow failure under conditions.
+ Unit test decorator to expect failure under conditions.
+
+ @param expect: Flag to check if failure is expected
+ @type expect: bool
+ """
+ if expect:
+ return unittest.expectedFailure
+ else:
+ return lambda orig: orig
+
+
+def allowed_failure(func):
+ """
+ Unit test decorator to allow failure.
+
+ Test runners each have different interpretations of what should be
+ the result of an @expectedFailure test if it succeeds. Some consider
+ it to be a pass; others a failure.
+
+ This decorator runs the test and, if it is a failure, reports the result
+ and considers it a skipped test.
+ """
+ def wrapper(*args, **kwargs):
+ try:
+ func(*args, **kwargs)
+ except Exception:
+ pywikibot.exception(tb=True)
+ raise unittest.SkipTest()
+ return wrapper
+
+
+def allowed_failure_if(expect):
+ """
+ Unit test decorator to allow failure under conditions.
@param expect: Flag to check if failure is allowed
@type expect: bool
"""
if expect:
- return unittest.expectedFailure
+ return allowed_failure
else:
return lambda orig: orig
--
To view, visit https://gerrit.wikimedia.org/r/178069
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia87dda2780a9fe4130b2820298f07f983d5db80b
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits