Hardenet test
@@ -36,6 +36,7 @@ class TestLazyAssert(LazyTestMixin, TestCase):
self.lazyAssertTrue(False)
with self.assertRaises(ZeroDivisionError):
1 / 0
+ with self.assertRaises(self.LazyAssertionError):
self.lazy_check()
def test_ok(self):
@@ -98,9 +99,18 @@ class LazyAssertRequests(LazyTestMixin, TestCase):
self.lazy_check()
def test_error(self):
- """example that an error is more important than a lazy test"""
+ """example that a more important error can be caught later
+ or than an assert in a lazy test"""
with self.lazy_assert_n_requests(1):
driver.request_count += 2 # then check requests
with self.assertRaises(ZeroDivisionError):
1 / 0
+ with self.assertRaises(self.LazyAssertionError) as cm:
self.lazy_check()
+ exc_class, exc_value, exc_traceback_str = cm.test_case.lazy_failure
+ self.assertTrue(issubclass(exc_class, AssertionError))
+ self.assertEqual(
+ ''.join(exc_value.args),
+ '1 != 2 : expected requests != real requests; checked by:\n with self.lazy_assert_n_requests(1):'
+ )
+ self.assertRegex(r'^File \n".*", line ', exc_traceback_str)
