Run the examples in `test`. Write the outcome of each example with one of the `DocTestRunner.report_*` methods, using the writer function `out`. `compileflags` is the set of compiler flags that should be used to execute examples. Return a TestResults insta
(self, test, compileflags, out)
| 1367 | #///////////////////////////////////////////////////////////////// |
| 1368 | |
| 1369 | def __run(self, test, compileflags, out): |
| 1370 | """ |
| 1371 | Run the examples in `test`. Write the outcome of each example |
| 1372 | with one of the `DocTestRunner.report_*` methods, using the |
| 1373 | writer function `out`. `compileflags` is the set of compiler |
| 1374 | flags that should be used to execute examples. Return a TestResults |
| 1375 | instance. The examples are run in the namespace `test.globs`. |
| 1376 | """ |
| 1377 | # Keep track of the number of failed, attempted, skipped examples. |
| 1378 | failures = attempted = skips = 0 |
| 1379 | |
| 1380 | # Save the option flags (since option directives can be used |
| 1381 | # to modify them). |
| 1382 | original_optionflags = self.optionflags |
| 1383 | |
| 1384 | SUCCESS, FAILURE, BOOM = range(3) # `outcome` state |
| 1385 | |
| 1386 | check = self._checker.check_output |
| 1387 | |
| 1388 | # Process each example. |
| 1389 | for examplenum, example in enumerate(test.examples): |
| 1390 | attempted += 1 |
| 1391 | |
| 1392 | # If REPORT_ONLY_FIRST_FAILURE is set, then suppress |
| 1393 | # reporting after the first failure. |
| 1394 | quiet = (self.optionflags & REPORT_ONLY_FIRST_FAILURE and |
| 1395 | failures > 0) |
| 1396 | |
| 1397 | # Merge in the example's options. |
| 1398 | self.optionflags = original_optionflags |
| 1399 | if example.options: |
| 1400 | for (optionflag, val) in example.options.items(): |
| 1401 | if val: |
| 1402 | self.optionflags |= optionflag |
| 1403 | else: |
| 1404 | self.optionflags &= ~optionflag |
| 1405 | |
| 1406 | # If 'SKIP' is set, then skip this example. |
| 1407 | if self.optionflags & SKIP: |
| 1408 | if not quiet: |
| 1409 | self.report_skip(out, test, example) |
| 1410 | skips += 1 |
| 1411 | continue |
| 1412 | |
| 1413 | # Record that we started this example. |
| 1414 | if not quiet: |
| 1415 | self.report_start(out, test, example) |
| 1416 | |
| 1417 | # Use a special filename for compile(), so we can retrieve |
| 1418 | # the source code during interactive debugging (see |
| 1419 | # __patched_linecache_getlines). |
| 1420 | filename = '<doctest %s[%d]>' % (test.name, examplenum) |
| 1421 | |
| 1422 | # Run the example in the given context (globs), and record |
| 1423 | # any exception that gets raised. (But don't intercept |
| 1424 | # keyboard interrupts.) |
| 1425 | try: |
| 1426 | # Don't blink! This is where the user's code gets run. |
no test coverage detected