(self)
| 384 | self.assertEqual('A tracebacklocals', formatted_exc) |
| 385 | |
| 386 | def test_addSubTest(self): |
| 387 | class Foo(unittest.TestCase): |
| 388 | def test_1(self): |
| 389 | nonlocal subtest |
| 390 | with self.subTest(foo=1): |
| 391 | subtest = self._subtest |
| 392 | try: |
| 393 | 1/0 |
| 394 | except ZeroDivisionError: |
| 395 | exc_info_tuple = sys.exc_info() |
| 396 | # Register an error by hand (to check the API) |
| 397 | result.addSubTest(test, subtest, exc_info_tuple) |
| 398 | # Now trigger a failure |
| 399 | self.fail("some recognizable failure") |
| 400 | |
| 401 | subtest = None |
| 402 | test = Foo('test_1') |
| 403 | result = unittest.TestResult() |
| 404 | |
| 405 | test.run(result) |
| 406 | |
| 407 | self.assertFalse(result.wasSuccessful()) |
| 408 | self.assertEqual(len(result.errors), 1) |
| 409 | self.assertEqual(len(result.failures), 1) |
| 410 | self.assertEqual(result.testsRun, 1) |
| 411 | self.assertEqual(result.shouldStop, False) |
| 412 | |
| 413 | test_case, formatted_exc = result.errors[0] |
| 414 | self.assertIs(test_case, subtest) |
| 415 | self.assertIn("ZeroDivisionError", formatted_exc) |
| 416 | test_case, formatted_exc = result.failures[0] |
| 417 | self.assertIs(test_case, subtest) |
| 418 | self.assertIn("some recognizable failure", formatted_exc) |
| 419 | |
| 420 | def testStackFrameTrimming(self): |
| 421 | class Frame(object): |
nothing calls this directly
no test coverage detected