I want to run doc-tests and get the number of failures, but not print any output. For example, I tried this:
with open(os.devnull, 'w') as sys.stdout:
tests_failed, tests_run = doctest.testmod(some_module,
optionflags=doctest.ELLIPSIS)
but this does not play nice with the test runner suite, which requires sys.stdout
to write to a JSON file.
How can I run doc-tests without printing any output?
sys.stdout
to write to a JSON file, do you need that JSON file to also include the results of these doctest runs? If not, my solution should work for you. If so, please clarify what you need.redirect_stdout
to write that file out as well, since it also accepts a file opened withopen()
. Then you wouldn't have restrictions aboutstdout
elsewhere in your test suite.