Message247667
I propose that we remove the paragraph before 'run_docstring_exmaples' in the doctest docs. It says that there's no intent to remove the function but that it is "rarely useful". However, it is in fact *very* useful, for any code that also uses testmod.
For example, a module I just wrote has this:
if __name__ == '__main__':
import doctest
flags = doctest.REPORT_NDIFF|doctest.FAIL_FAST
if len(sys.argv) > 1:
name = sys.argv[1]
if name in globals():
obj = globals()[name]
else:
obj = __test__[name]
doctest.run_docstring_examples(obj, globals(), name=name,
optionflags=flags)
else:
fail, total = doctest.testmod(optionflags=flags)
print("{} failures out of {} tests".format(fail, total))
This makes the module its own test runner: if I get doctest failures, I can re-run a *specific* doctest while debugging the problem, and is the obvious application of run_docstring_examples.
The attached patch also clarifies the fact that it works on strings. It also adds the above example to the soapbox section of the docs. I'm less interested in that change than in the clarification that strings work :)
Someday perhaps I'll propose the addition of the equivalent to unittest.main for doctest. |
|
Date |
User |
Action |
Args |
2015-07-30 13:27:11 | r.david.murray | set | recipients:
+ r.david.murray |
2015-07-30 13:27:10 | r.david.murray | set | messageid: <1438262830.97.0.532585638369.issue24756@psf.upfronthosting.co.za> |
2015-07-30 13:27:10 | r.david.murray | link | issue24756 messages |
2015-07-30 13:27:10 | r.david.murray | create | |
|