r"""Run the test case without results and without catching exceptions The unit test framework includes a debug method on test cases and test suites to support post-mortem debugging. The test code is run in such a way that errors are not caught. This way a
(self)
| 2255 | ) |
| 2256 | |
| 2257 | def debug(self): |
| 2258 | r"""Run the test case without results and without catching exceptions |
| 2259 | |
| 2260 | The unit test framework includes a debug method on test cases |
| 2261 | and test suites to support post-mortem debugging. The test code |
| 2262 | is run in such a way that errors are not caught. This way a |
| 2263 | caller can catch the errors and initiate post-mortem debugging. |
| 2264 | |
| 2265 | The DocTestCase provides a debug method that raises |
| 2266 | UnexpectedException errors if there is an unexpected |
| 2267 | exception: |
| 2268 | |
| 2269 | >>> test = DocTestParser().get_doctest('>>> raise KeyError\n42', |
| 2270 | ... {}, 'foo', 'foo.py', 0) |
| 2271 | >>> case = DocTestCase(test) |
| 2272 | >>> try: |
| 2273 | ... case.debug() |
| 2274 | ... except UnexpectedException as f: |
| 2275 | ... failure = f |
| 2276 | |
| 2277 | The UnexpectedException contains the test, the example, and |
| 2278 | the original exception: |
| 2279 | |
| 2280 | >>> failure.test is test |
| 2281 | True |
| 2282 | |
| 2283 | >>> failure.example.want |
| 2284 | '42\n' |
| 2285 | |
| 2286 | >>> exc_info = failure.exc_info |
| 2287 | >>> raise exc_info[1] # Already has the traceback |
| 2288 | Traceback (most recent call last): |
| 2289 | ... |
| 2290 | KeyError |
| 2291 | |
| 2292 | If the output doesn't match, then a DocTestFailure is raised: |
| 2293 | |
| 2294 | >>> test = DocTestParser().get_doctest(''' |
| 2295 | ... >>> x = 1 |
| 2296 | ... >>> x |
| 2297 | ... 2 |
| 2298 | ... ''', {}, 'foo', 'foo.py', 0) |
| 2299 | >>> case = DocTestCase(test) |
| 2300 | |
| 2301 | >>> try: |
| 2302 | ... case.debug() |
| 2303 | ... except DocTestFailure as f: |
| 2304 | ... failure = f |
| 2305 | |
| 2306 | DocTestFailure objects provide access to the test: |
| 2307 | |
| 2308 | >>> failure.test is test |
| 2309 | True |
| 2310 | |
| 2311 | As well as to the example: |
| 2312 | |
| 2313 | >>> failure.example.want |
| 2314 | '2\n' |
nothing calls this directly
no test coverage detected