Bug 1595814 - [marionette] Don't import private _ExpectedFailure and _UnexpectedSuccess classes from unittest. r=whimboo,marionette-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D53312

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Rishi Gupta 2019-11-21 20:26:12 +00:00
Родитель 1d81724432
Коммит f8a2da8835
1 изменённых файлов: 27 добавлений и 13 удалений

Просмотреть файл

@ -14,11 +14,7 @@ import unittest
import warnings
import weakref
from unittest.case import (
_ExpectedFailure,
_UnexpectedSuccess,
SkipTest,
)
from unittest.case import SkipTest
from marionette_driver.errors import (
TimeoutException,
@ -36,6 +32,24 @@ def _wraps_parameterized(func, func_suffix, args, kwargs):
return wrapper
class ExpectedFailure(Exception):
"""
Raise this when a test is expected to fail.
This is an implementation detail.
"""
def __init__(self, exc_info):
super(ExpectedFailure, self).__init__()
self.exc_info = exc_info
class UnexpectedSuccess(Exception):
"""
The test was supposed to fail, but it didn't!
"""
class MetaParameterized(type):
"""
A metaclass that allow a class to use decorators.
@ -135,14 +149,14 @@ class CommonTestCase(unittest.TestCase):
try:
self.setUp()
except Exception:
raise _ExpectedFailure(sys.exc_info())
raise ExpectedFailure(sys.exc_info())
else:
self.setUp()
except SkipTest as e:
self._addSkip(result, str(e))
except (KeyboardInterrupt, UnresponsiveInstanceException):
raise
except _ExpectedFailure as e:
except ExpectedFailure as e:
expected_failure(result, e.exc_info)
except Exception:
self._enter_pm()
@ -153,8 +167,8 @@ class CommonTestCase(unittest.TestCase):
try:
testMethod()
except Exception:
raise _ExpectedFailure(sys.exc_info())
raise _UnexpectedSuccess
raise ExpectedFailure(sys.exc_info())
raise UnexpectedSuccess
else:
testMethod()
except self.failureException:
@ -162,9 +176,9 @@ class CommonTestCase(unittest.TestCase):
result.addFailure(self, sys.exc_info())
except (KeyboardInterrupt, UnresponsiveInstanceException):
raise
except _ExpectedFailure as e:
except ExpectedFailure as e:
expected_failure(result, e.exc_info)
except _UnexpectedSuccess:
except UnexpectedSuccess:
addUnexpectedSuccess = getattr(result, 'addUnexpectedSuccess', None)
if addUnexpectedSuccess is not None:
addUnexpectedSuccess(self)
@ -185,12 +199,12 @@ class CommonTestCase(unittest.TestCase):
try:
self.tearDown()
except Exception:
raise _ExpectedFailure(sys.exc_info())
raise ExpectedFailure(sys.exc_info())
else:
self.tearDown()
except (KeyboardInterrupt, UnresponsiveInstanceException):
raise
except _ExpectedFailure as e:
except ExpectedFailure as e:
expected_failure(result, e.exc_info)
except Exception:
self._enter_pm()