Stop using deprecated `skip()` internally
This commit is contained in:
parent
1481272843
commit
b3394b2a5c
|
@ -19,7 +19,6 @@ import copy
|
||||||
import functools
|
import functools
|
||||||
import itertools
|
import itertools
|
||||||
import sys
|
import sys
|
||||||
import types
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from extras import (
|
from extras import (
|
||||||
|
@ -40,7 +39,6 @@ from testtools.compat import (
|
||||||
from testtools.matchers import (
|
from testtools.matchers import (
|
||||||
Annotate,
|
Annotate,
|
||||||
Contains,
|
Contains,
|
||||||
Equals,
|
|
||||||
MatchesAll,
|
MatchesAll,
|
||||||
MatchesException,
|
MatchesException,
|
||||||
MismatchError,
|
MismatchError,
|
||||||
|
@ -59,6 +57,7 @@ from testtools.testresult import (
|
||||||
|
|
||||||
wraps = try_import('functools.wraps')
|
wraps = try_import('functools.wraps')
|
||||||
|
|
||||||
|
|
||||||
class TestSkipped(Exception):
|
class TestSkipped(Exception):
|
||||||
"""Raised within TestCase.run() when a test is skipped."""
|
"""Raised within TestCase.run() when a test is skipped."""
|
||||||
TestSkipped = try_import('unittest.case.SkipTest', TestSkipped)
|
TestSkipped = try_import('unittest.case.SkipTest', TestSkipped)
|
||||||
|
@ -76,6 +75,7 @@ _UnexpectedSuccess = try_import(
|
||||||
_UnexpectedSuccess = try_import(
|
_UnexpectedSuccess = try_import(
|
||||||
'unittest2.case._UnexpectedSuccess', _UnexpectedSuccess)
|
'unittest2.case._UnexpectedSuccess', _UnexpectedSuccess)
|
||||||
|
|
||||||
|
|
||||||
class _ExpectedFailure(Exception):
|
class _ExpectedFailure(Exception):
|
||||||
"""An expected failure occured.
|
"""An expected failure occured.
|
||||||
|
|
||||||
|
@ -424,12 +424,14 @@ class TestCase(unittest.TestCase):
|
||||||
def match(self, matchee):
|
def match(self, matchee):
|
||||||
if not issubclass(matchee[0], excClass):
|
if not issubclass(matchee[0], excClass):
|
||||||
reraise(*matchee)
|
reraise(*matchee)
|
||||||
|
|
||||||
class CaptureMatchee(object):
|
class CaptureMatchee(object):
|
||||||
def match(self, matchee):
|
def match(self, matchee):
|
||||||
self.matchee = matchee[1]
|
self.matchee = matchee[1]
|
||||||
capture = CaptureMatchee()
|
capture = CaptureMatchee()
|
||||||
matcher = Raises(MatchesAll(ReRaiseOtherTypes(),
|
matcher = Raises(
|
||||||
MatchesException(excClass), capture))
|
MatchesAll(ReRaiseOtherTypes(),
|
||||||
|
MatchesException(excClass), capture))
|
||||||
our_callable = Nullary(callableObj, *args, **kwargs)
|
our_callable = Nullary(callableObj, *args, **kwargs)
|
||||||
self.assertThat(our_callable, matcher)
|
self.assertThat(our_callable, matcher)
|
||||||
return capture.matchee
|
return capture.matchee
|
||||||
|
@ -471,13 +473,14 @@ class TestCase(unittest.TestCase):
|
||||||
"""Check that matchee is matched by matcher, but delay the assertion failure.
|
"""Check that matchee is matched by matcher, but delay the assertion failure.
|
||||||
|
|
||||||
This method behaves similarly to ``assertThat``, except that a failed
|
This method behaves similarly to ``assertThat``, except that a failed
|
||||||
match does not exit the test immediately. The rest of the test code will
|
match does not exit the test immediately. The rest of the test code
|
||||||
continue to run, and the test will be marked as failing after the test
|
will continue to run, and the test will be marked as failing after the
|
||||||
has finished.
|
test has finished.
|
||||||
|
|
||||||
:param matchee: An object to match with matcher.
|
:param matchee: An object to match with matcher.
|
||||||
:param matcher: An object meeting the testtools.Matcher protocol.
|
:param matcher: An object meeting the testtools.Matcher protocol.
|
||||||
:param message: If specified, show this message with any failed match.
|
:param message: If specified, show this message with any failed match.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
mismatch_error = self._matchHelper(matchee, matcher, message, verbose)
|
mismatch_error = self._matchHelper(matchee, matcher, message, verbose)
|
||||||
|
|
||||||
|
@ -559,7 +562,7 @@ class TestCase(unittest.TestCase):
|
||||||
return '%s-%d' % (prefix, self.getUniqueInteger())
|
return '%s-%d' % (prefix, self.getUniqueInteger())
|
||||||
|
|
||||||
def onException(self, exc_info, tb_label='traceback'):
|
def onException(self, exc_info, tb_label='traceback'):
|
||||||
"""Called when an exception propogates from test code.
|
"""Called when an exception propagates from test code.
|
||||||
|
|
||||||
:seealso addOnException:
|
:seealso addOnException:
|
||||||
"""
|
"""
|
||||||
|
@ -811,7 +814,8 @@ def ErrorHolder(test_id, error, short_description=None, details=None):
|
||||||
:param short_description: An optional short description of the test.
|
:param short_description: An optional short description of the test.
|
||||||
:param details: Outcome details as accepted by addSuccess etc.
|
:param details: Outcome details as accepted by addSuccess etc.
|
||||||
"""
|
"""
|
||||||
return PlaceHolder(test_id, short_description=short_description,
|
return PlaceHolder(
|
||||||
|
test_id, short_description=short_description,
|
||||||
details=details, outcome='addError', error=error)
|
details=details, outcome='addError', error=error)
|
||||||
|
|
||||||
|
|
||||||
|
@ -906,6 +910,7 @@ def skipIf(condition, reason):
|
||||||
"""A decorator to skip a test if the condition is true."""
|
"""A decorator to skip a test if the condition is true."""
|
||||||
if condition:
|
if condition:
|
||||||
return skip(reason)
|
return skip(reason)
|
||||||
|
|
||||||
def _id(obj):
|
def _id(obj):
|
||||||
return obj
|
return obj
|
||||||
return _id
|
return _id
|
||||||
|
@ -915,6 +920,7 @@ def skipUnless(condition, reason):
|
||||||
"""A decorator to skip a test unless the condition is true."""
|
"""A decorator to skip a test unless the condition is true."""
|
||||||
if not condition:
|
if not condition:
|
||||||
return skip(reason)
|
return skip(reason)
|
||||||
|
|
||||||
def _id(obj):
|
def _id(obj):
|
||||||
return obj
|
return obj
|
||||||
return _id
|
return _id
|
||||||
|
|
|
@ -1412,14 +1412,16 @@ require_py27_minimum = skipIf(
|
||||||
class TestSkipping(TestCase):
|
class TestSkipping(TestCase):
|
||||||
"""Tests for skipping of tests functionality."""
|
"""Tests for skipping of tests functionality."""
|
||||||
|
|
||||||
run_test_with = FullStackRunTest
|
run_tests_with = FullStackRunTest
|
||||||
|
|
||||||
def test_skip_causes_skipException(self):
|
def test_skip_causes_skipException(self):
|
||||||
self.assertThat(lambda:self.skip("Skip this test"),
|
self.assertThat(
|
||||||
|
lambda: self.skip("Skip this test"),
|
||||||
Raises(MatchesException(self.skipException)))
|
Raises(MatchesException(self.skipException)))
|
||||||
|
|
||||||
def test_can_use_skipTest(self):
|
def test_can_use_skipTest(self):
|
||||||
self.assertThat(lambda:self.skipTest("Skip this test"),
|
self.assertThat(
|
||||||
|
lambda: self.skipTest("Skip this test"),
|
||||||
Raises(MatchesException(self.skipException)))
|
Raises(MatchesException(self.skipException)))
|
||||||
|
|
||||||
def test_skip_without_reason_works(self):
|
def test_skip_without_reason_works(self):
|
||||||
|
@ -1430,14 +1432,16 @@ class TestSkipping(TestCase):
|
||||||
result = ExtendedTestResult()
|
result = ExtendedTestResult()
|
||||||
case.run(result)
|
case.run(result)
|
||||||
self.assertEqual('addSkip', result._events[1][0])
|
self.assertEqual('addSkip', result._events[1][0])
|
||||||
self.assertEqual('no reason given.',
|
self.assertEqual(
|
||||||
|
'no reason given.',
|
||||||
result._events[1][2]['reason'].as_text())
|
result._events[1][2]['reason'].as_text())
|
||||||
|
|
||||||
def test_skipException_in_setup_calls_result_addSkip(self):
|
def test_skipException_in_setup_calls_result_addSkip(self):
|
||||||
class TestThatRaisesInSetUp(TestCase):
|
class TestThatRaisesInSetUp(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
TestCase.setUp(self)
|
TestCase.setUp(self)
|
||||||
self.skip("skipping this test")
|
self.skipTest("skipping this test")
|
||||||
|
|
||||||
def test_that_passes(self):
|
def test_that_passes(self):
|
||||||
pass
|
pass
|
||||||
calls = []
|
calls = []
|
||||||
|
@ -1445,72 +1449,103 @@ class TestSkipping(TestCase):
|
||||||
test = TestThatRaisesInSetUp("test_that_passes")
|
test = TestThatRaisesInSetUp("test_that_passes")
|
||||||
test.run(result)
|
test.run(result)
|
||||||
case = result._events[0][1]
|
case = result._events[0][1]
|
||||||
self.assertEqual([('startTest', case),
|
self.assertEqual(
|
||||||
('addSkip', case, "skipping this test"), ('stopTest', case)],
|
[('startTest', case),
|
||||||
|
('addSkip', case, "skipping this test"),
|
||||||
|
('stopTest', case)],
|
||||||
calls)
|
calls)
|
||||||
|
|
||||||
def test_skipException_in_test_method_calls_result_addSkip(self):
|
def test_skipException_in_test_method_calls_result_addSkip(self):
|
||||||
class SkippingTest(TestCase):
|
class SkippingTest(TestCase):
|
||||||
def test_that_raises_skipException(self):
|
def test_that_raises_skipException(self):
|
||||||
self.skip("skipping this test")
|
self.skipTest("skipping this test")
|
||||||
result = Python27TestResult()
|
events = []
|
||||||
|
result = Python27TestResult(events)
|
||||||
test = SkippingTest("test_that_raises_skipException")
|
test = SkippingTest("test_that_raises_skipException")
|
||||||
test.run(result)
|
test.run(result)
|
||||||
case = result._events[0][1]
|
case = result._events[0][1]
|
||||||
self.assertEqual([('startTest', case),
|
self.assertEqual(
|
||||||
('addSkip', case, "skipping this test"), ('stopTest', case)],
|
[('startTest', case),
|
||||||
result._events)
|
('addSkip', case, "skipping this test"),
|
||||||
|
('stopTest', case)],
|
||||||
|
events)
|
||||||
|
|
||||||
|
def test_different_skipException_in_test_method_calls_result_addSkip(self):
|
||||||
|
class SkippingTest(TestCase):
|
||||||
|
skipException = ValueError
|
||||||
|
|
||||||
|
def test_that_raises_skipException(self):
|
||||||
|
self.skipTest("skipping this test")
|
||||||
|
|
||||||
|
events = []
|
||||||
|
result = Python27TestResult(events)
|
||||||
|
test = SkippingTest("test_that_raises_skipException")
|
||||||
|
test.run(result)
|
||||||
|
case = result._events[0][1]
|
||||||
|
self.assertEqual(
|
||||||
|
[('startTest', case),
|
||||||
|
('addSkip', case, "skipping this test"),
|
||||||
|
('stopTest', case)],
|
||||||
|
events)
|
||||||
|
|
||||||
def test_skip__in_setup_with_old_result_object_calls_addSuccess(self):
|
def test_skip__in_setup_with_old_result_object_calls_addSuccess(self):
|
||||||
|
|
||||||
class SkippingTest(TestCase):
|
class SkippingTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
TestCase.setUp(self)
|
TestCase.setUp(self)
|
||||||
raise self.skipException("skipping this test")
|
raise self.skipException("skipping this test")
|
||||||
|
|
||||||
def test_that_raises_skipException(self):
|
def test_that_raises_skipException(self):
|
||||||
pass
|
pass
|
||||||
result = Python26TestResult()
|
|
||||||
|
events = []
|
||||||
|
result = Python26TestResult(events)
|
||||||
test = SkippingTest("test_that_raises_skipException")
|
test = SkippingTest("test_that_raises_skipException")
|
||||||
test.run(result)
|
test.run(result)
|
||||||
self.assertEqual('addSuccess', result._events[1][0])
|
self.assertEqual('addSuccess', events[1][0])
|
||||||
|
|
||||||
def test_skip_with_old_result_object_calls_addError(self):
|
def test_skip_with_old_result_object_calls_addError(self):
|
||||||
class SkippingTest(TestCase):
|
class SkippingTest(TestCase):
|
||||||
def test_that_raises_skipException(self):
|
def test_that_raises_skipException(self):
|
||||||
raise self.skipException("skipping this test")
|
raise self.skipException("skipping this test")
|
||||||
result = Python26TestResult()
|
events = []
|
||||||
|
result = Python26TestResult(events)
|
||||||
test = SkippingTest("test_that_raises_skipException")
|
test = SkippingTest("test_that_raises_skipException")
|
||||||
test.run(result)
|
test.run(result)
|
||||||
self.assertEqual('addSuccess', result._events[1][0])
|
self.assertEqual('addSuccess', events[1][0])
|
||||||
|
|
||||||
def test_skip_decorator(self):
|
def test_skip_decorator(self):
|
||||||
class SkippingTest(TestCase):
|
class SkippingTest(TestCase):
|
||||||
@skip("skipping this test")
|
@skip("skipping this test")
|
||||||
def test_that_is_decorated_with_skip(self):
|
def test_that_is_decorated_with_skip(self):
|
||||||
self.fail()
|
self.fail()
|
||||||
result = Python26TestResult()
|
events = []
|
||||||
|
result = Python26TestResult(events)
|
||||||
test = SkippingTest("test_that_is_decorated_with_skip")
|
test = SkippingTest("test_that_is_decorated_with_skip")
|
||||||
test.run(result)
|
test.run(result)
|
||||||
self.assertEqual('addSuccess', result._events[1][0])
|
self.assertEqual('addSuccess', events[1][0])
|
||||||
|
|
||||||
def test_skipIf_decorator(self):
|
def test_skipIf_decorator(self):
|
||||||
class SkippingTest(TestCase):
|
class SkippingTest(TestCase):
|
||||||
@skipIf(True, "skipping this test")
|
@skipIf(True, "skipping this test")
|
||||||
def test_that_is_decorated_with_skipIf(self):
|
def test_that_is_decorated_with_skipIf(self):
|
||||||
self.fail()
|
self.fail()
|
||||||
result = Python26TestResult()
|
events = []
|
||||||
|
result = Python26TestResult(events)
|
||||||
test = SkippingTest("test_that_is_decorated_with_skipIf")
|
test = SkippingTest("test_that_is_decorated_with_skipIf")
|
||||||
test.run(result)
|
test.run(result)
|
||||||
self.assertEqual('addSuccess', result._events[1][0])
|
self.assertEqual('addSuccess', events[1][0])
|
||||||
|
|
||||||
def test_skipUnless_decorator(self):
|
def test_skipUnless_decorator(self):
|
||||||
class SkippingTest(TestCase):
|
class SkippingTest(TestCase):
|
||||||
@skipUnless(False, "skipping this test")
|
@skipUnless(False, "skipping this test")
|
||||||
def test_that_is_decorated_with_skipUnless(self):
|
def test_that_is_decorated_with_skipUnless(self):
|
||||||
self.fail()
|
self.fail()
|
||||||
result = Python26TestResult()
|
events = []
|
||||||
|
result = Python26TestResult(events)
|
||||||
test = SkippingTest("test_that_is_decorated_with_skipUnless")
|
test = SkippingTest("test_that_is_decorated_with_skipUnless")
|
||||||
test.run(result)
|
test.run(result)
|
||||||
self.assertEqual('addSuccess', result._events[1][0])
|
self.assertEqual('addSuccess', events[1][0])
|
||||||
|
|
||||||
def check_skip_decorator_does_not_run_setup(self, decorator, reason):
|
def check_skip_decorator_does_not_run_setup(self, decorator, reason):
|
||||||
class SkippingTest(TestCase):
|
class SkippingTest(TestCase):
|
||||||
|
|
Loading…
Reference in New Issue