(self)
| 2201 | self.assertEqual(callbacks, [branch_1, branch_2, leaf_3, leaf_1, leaf_2]) |
| 2202 | |
| 2203 | def test_execute_robust(self): |
| 2204 | class MyException(Exception): |
| 2205 | pass |
| 2206 | |
| 2207 | def hook(): |
| 2208 | self.callback_called = True |
| 2209 | raise MyException("robust callback") |
| 2210 | |
| 2211 | with self.assertLogs("django.test", "ERROR") as cm: |
| 2212 | with self.captureOnCommitCallbacks(execute=True) as callbacks: |
| 2213 | transaction.on_commit(hook, robust=True) |
| 2214 | |
| 2215 | self.assertEqual(len(callbacks), 1) |
| 2216 | self.assertIs(self.callback_called, True) |
| 2217 | |
| 2218 | log_record = cm.records[0] |
| 2219 | self.assertEqual( |
| 2220 | log_record.getMessage(), |
| 2221 | "Error calling CaptureOnCommitCallbacksTests.test_execute_robust.<locals>." |
| 2222 | "hook in on_commit() (robust callback).", |
| 2223 | ) |
| 2224 | self.assertIsNotNone(log_record.exc_info) |
| 2225 | raised_exception = log_record.exc_info[1] |
| 2226 | self.assertIsInstance(raised_exception, MyException) |
| 2227 | self.assertEqual(str(raised_exception), "robust callback") |
| 2228 | |
| 2229 | def test_execute_robust_with_callback_as_partial(self): |
| 2230 | class MyException(Exception): |
nothing calls this directly
no test coverage detected