)
from testtools.matchers import (
Equals,
+ MatchesException,
+ Raises,
)
from testtools.tests.helpers import (
an_exc_info,
def test_assertRaises_fails_when_different_error_raised(self):
# assertRaises re-raises an exception that it didn't expect.
- self.assertRaises(
- ZeroDivisionError,
- self.assertRaises,
- RuntimeError, self.raiseError, ZeroDivisionError)
+ self.assertThat(lambda: self.assertRaises(RuntimeError,
+ self.raiseError, ZeroDivisionError),
+ Raises(MatchesException(ZeroDivisionError)))
def test_assertRaises_returns_the_raised_exception(self):
# assertRaises returns the exception object that was raised. This is
def raiseKeyboardInterrupt():
raise KeyboardInterrupt()
self.test.addCleanup(raiseKeyboardInterrupt)
- self.assertRaises(
- KeyboardInterrupt, self.test.run, self.logging_result)
+ self.assertThat(lambda:self.test.run(self.logging_result),
+ Raises(MatchesException(KeyboardInterrupt)))
def test_all_errors_from_MultipleExceptions_reported(self):
# When a MultipleExceptions exception is caught, all the errors are
"""Tests for skipping of tests functionality."""
def test_skip_causes_skipException(self):
- self.assertRaises(self.skipException, self.skip, "Skip this test")
+ self.assertThat(lambda:self.skip("Skip this test"),
+ Raises(MatchesException(self.skipException)))
def test_can_use_skipTest(self):
- self.assertRaises(self.skipException, self.skipTest, "Skip this test")
+ self.assertThat(lambda:self.skipTest("Skip this test"),
+ Raises(MatchesException(self.skipException)))
def test_skip_without_reason_works(self):
class Test(TestCase):
test.run(result)
case = result._events[0][1]
self.assertEqual([('startTest', case),
- ('addSkip', case, "Text attachment: reason\n------------\n"
- "skipping this test\n------------\n"), ('stopTest', case)],
+ ('addSkip', case, "skipping this test"), ('stopTest', case)],
calls)
def test_skipException_in_test_method_calls_result_addSkip(self):
test.run(result)
case = result._events[0][1]
self.assertEqual([('startTest', case),
- ('addSkip', case, "Text attachment: reason\n------------\n"
- "skipping this test\n------------\n"), ('stopTest', case)],
+ ('addSkip', case, "skipping this test"), ('stopTest', case)],
result._events)
def test_skip__in_setup_with_old_result_object_calls_addSuccess(self):
class Case(TestCase):
def method(self):
self.addOnException(events.index)
- self.assertRaises(ValueError, self.onException, an_exc_info)
+ self.assertThat(lambda: self.onException(an_exc_info),
+ Raises(MatchesException(ValueError)))
case = Case("method")
case.run()
self.assertThat(events, Equals([]))