Commit c65eb4ef authored by Vincent Pelletier's avatar Vincent Pelletier

tests: Reuse unittest's functions & classes when present.

Fixes unittest.expectedFailure usage, allowing phasing out
backportUnittest gradually (at least for the backport part).
parent 3f8b6a39
...@@ -9,7 +9,16 @@ import unittest ...@@ -9,7 +9,16 @@ import unittest
import sys import sys
import time import time
class SkipTest(Exception): try:
SkipTest = unittest.SkipTest
_ExpectedFailure = unittest.case._ExpectedFailure
_UnexpectedSuccess = unittest.case._UnexpectedSuccess
skip = unittest.skip
skipIf = unittest.skipIf
skipUnless = unittest.skipUnless
expectedFailure = unittest.expectedFailure
except AttributeError:
class SkipTest(Exception):
""" """
Raise this exception in a test to skip it. Raise this exception in a test to skip it.
...@@ -18,7 +27,7 @@ class SkipTest(Exception): ...@@ -18,7 +27,7 @@ class SkipTest(Exception):
""" """
pass pass
class _ExpectedFailure(Exception): class _ExpectedFailure(Exception):
""" """
Raise this when a test is expected to fail. Raise this when a test is expected to fail.
...@@ -29,25 +38,16 @@ class _ExpectedFailure(Exception): ...@@ -29,25 +38,16 @@ class _ExpectedFailure(Exception):
Exception.__init__(self) Exception.__init__(self)
self.exc_info = exc_info self.exc_info = exc_info
class _UnexpectedSuccess(Exception): class _UnexpectedSuccess(Exception):
""" """
The test was supposed to fail, but it didn't! The test was supposed to fail, but it didn't!
""" """
pass pass
class SetupSiteError(Exception): def _id(obj):
"""
The ERP5 Site could not have been setup.
This is raised when the site could not have been created in a previous
test. We want this to count as an error, but we do not want this to happear
in traceback for readability.
"""
pass
def _id(obj):
return obj return obj
def skip(reason): def skip(reason):
""" """
Unconditionally skip a test. Unconditionally skip a test.
""" """
...@@ -63,7 +63,7 @@ def skip(reason): ...@@ -63,7 +63,7 @@ def skip(reason):
return skip_wrapper return skip_wrapper
return decorator return decorator
def skipIf(condition, reason): def skipIf(condition, reason):
""" """
Skip a test if the condition is true. Skip a test if the condition is true.
""" """
...@@ -71,7 +71,7 @@ def skipIf(condition, reason): ...@@ -71,7 +71,7 @@ def skipIf(condition, reason):
return skip(reason) return skip(reason)
return _id return _id
def skipUnless(condition, reason): def skipUnless(condition, reason):
""" """
Skip a test unless the condition is true. Skip a test unless the condition is true.
""" """
...@@ -80,7 +80,7 @@ def skipUnless(condition, reason): ...@@ -80,7 +80,7 @@ def skipUnless(condition, reason):
return _id return _id
def expectedFailure(func): def expectedFailure(func):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
try: try:
func(*args, **kwargs) func(*args, **kwargs)
...@@ -91,6 +91,15 @@ def expectedFailure(func): ...@@ -91,6 +91,15 @@ def expectedFailure(func):
wrapper.__doc__ = func.__doc__ wrapper.__doc__ = func.__doc__
return wrapper return wrapper
class SetupSiteError(Exception):
"""
The ERP5 Site could not have been setup.
This is raised when the site could not have been created in a previous
test. We want this to count as an error, but we do not want this to happear
in traceback for readability.
"""
pass
class TestCase(unittest.TestCase): class TestCase(unittest.TestCase):
"""We redefine here the run() method, and add a skipTest() method. """We redefine here the run() method, and add a skipTest() method.
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment