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
import sys
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.
......@@ -18,7 +27,7 @@ class SkipTest(Exception):
"""
pass
class _ExpectedFailure(Exception):
class _ExpectedFailure(Exception):
"""
Raise this when a test is expected to fail.
......@@ -29,25 +38,16 @@ class _ExpectedFailure(Exception):
Exception.__init__(self)
self.exc_info = exc_info
class _UnexpectedSuccess(Exception):
class _UnexpectedSuccess(Exception):
"""
The test was supposed to fail, but it didn't!
"""
pass
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
def _id(obj):
def _id(obj):
return obj
def skip(reason):
def skip(reason):
"""
Unconditionally skip a test.
"""
......@@ -63,7 +63,7 @@ def skip(reason):
return skip_wrapper
return decorator
def skipIf(condition, reason):
def skipIf(condition, reason):
"""
Skip a test if the condition is true.
"""
......@@ -71,7 +71,7 @@ def skipIf(condition, reason):
return skip(reason)
return _id
def skipUnless(condition, reason):
def skipUnless(condition, reason):
"""
Skip a test unless the condition is true.
"""
......@@ -80,7 +80,7 @@ def skipUnless(condition, reason):
return _id
def expectedFailure(func):
def expectedFailure(func):
def wrapper(*args, **kwargs):
try:
func(*args, **kwargs)
......@@ -91,6 +91,15 @@ def expectedFailure(func):
wrapper.__doc__ = func.__doc__
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):
"""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