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 tuple `(f, t
(self, test, compileflags, out)
| 1296 | #///////////////////////////////////////////////////////////////// |
| 1297 | |
| 1298 | def __run(self, test, compileflags, out): |
| 1299 | """ |
| 1300 | Run the examples in `test`. Write the outcome of each example |
| 1301 | with one of the `DocTestRunner.report_*` methods, using the |
| 1302 | writer function `out`. `compileflags` is the set of compiler |
| 1303 | flags that should be used to execute examples. Return a tuple |
| 1304 | `(f, t)`, where `t` is the number of examples tried, and `f` |
| 1305 | is the number of examples that failed. The examples are run |
| 1306 | in the namespace `test.globs`. |
| 1307 | """ |
| 1308 | # Keep track of the number of failures and tries. |
| 1309 | failures = tries = 0 |
| 1310 | |
| 1311 | # Save the option flags (since option directives can be used |
| 1312 | # to modify them). |
| 1313 | original_optionflags = self.optionflags |
| 1314 | |
| 1315 | SUCCESS, FAILURE, BOOM = range(3) # `outcome` state |
| 1316 | |
| 1317 | check = self._checker.check_output |
| 1318 | |
| 1319 | # Process each example. |
| 1320 | for examplenum, example in enumerate(test.examples): |
| 1321 | |
| 1322 | # If REPORT_ONLY_FIRST_FAILURE is set, then suppress |
| 1323 | # reporting after the first failure. |
| 1324 | quiet = (self.optionflags & REPORT_ONLY_FIRST_FAILURE and |
| 1325 | failures > 0) |
| 1326 | |
| 1327 | # Merge in the example's options. |
| 1328 | self.optionflags = original_optionflags |
| 1329 | if example.options: |
| 1330 | for (optionflag, val) in example.options.items(): |
| 1331 | if val: |
| 1332 | self.optionflags |= optionflag |
| 1333 | else: |
| 1334 | self.optionflags &= ~optionflag |
| 1335 | |
| 1336 | # If 'SKIP' is set, then skip this example. |
| 1337 | if self.optionflags & SKIP: |
| 1338 | continue |
| 1339 | |
| 1340 | # Record that we started this example. |
| 1341 | tries += 1 |
| 1342 | if not quiet: |
| 1343 | self.report_start(out, test, example) |
| 1344 | |
| 1345 | # Use a special filename for compile(), so we can retrieve |
| 1346 | # the source code during interactive debugging (see |
| 1347 | # __patched_linecache_getlines). |
| 1348 | filename = '<doctest %s[%d]>' % (test.name, examplenum) |
| 1349 | |
| 1350 | # Run the example in the given context (globs), and record |
| 1351 | # any exception that gets raised. (But don't intercept |
| 1352 | # keyboard interrupts.) |
| 1353 | try: |
| 1354 | # Don't blink! This is where the user's code gets run. |
| 1355 | exec(compile(example.source, filename, "single", |
no test coverage detected