diff --git a/CHANGES b/CHANGES index 07666681c..90fb4d812 100644 --- a/CHANGES +++ b/CHANGES @@ -45,6 +45,9 @@ New features added Release 0.5.1 (in development) ============================== +* #67: Output warnings about failed doctests in the doctest extension + even when running in quiet mode. + * #72: In pngmath, make it possible to give a full path to LaTeX and dvipng on Windows. For that to work, the ``pngmath_latex`` and ``pngmath_dvipng`` options are no longer split into command and diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 09d37de28..5a1bc801c 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -266,12 +266,13 @@ class Builder(object): # finish (write static files etc.) self.finish() + status = self.app.statuscode == 0 and 'succeeded' or 'finished with problems' if self.app._warncount: - self.info(bold('build succeeded, %s warning%s.' % - (self.app._warncount, + self.info(bold('build %s, %s warning%s.' % + (status, self.app._warncount, self.app._warncount != 1 and 's' or ''))) else: - self.info(bold('build succeeded.')) + self.info(bold('build %s.' % status)) def write(self, build_docnames, updated_docnames, method='update'): if build_docnames is None or build_docnames == ['__all__']: diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index 8212028dd..8651526e4 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -184,6 +184,12 @@ Results of doctest builder run on %s self.info(text, nonl=True) self.outfile.write(text) + def _warn_out(self, text): + self.info(text, nonl=True) + if self.app.quiet: + self.warn(text) + self.outfile.write(text) + def get_target_uri(self, docname, typ=None): return '' @@ -205,6 +211,9 @@ Doctest summary self.setup_failures, s(self.setup_failures))) self.outfile.close() + if self.total_failures or self.setup_failures: + self.app.statuscode = 1 + sys.path[0:0] = self.config.doctest_path def write(self, build_docnames, updated_docnames, method='update'): @@ -287,7 +296,7 @@ Doctest summary setup_doctest.globs = ns old_f = self.setup_runner.failures self.type = 'exec' # the snippet may contain multiple statements - self.setup_runner.run(setup_doctest, out=self._out, + self.setup_runner.run(setup_doctest, out=self._warn_out, clear_globs=False) if self.setup_runner.failures > old_f: # don't run the group @@ -297,8 +306,6 @@ Doctest summary test = parser.get_doctest(code[0].code, {}, group.name, filename, code[0].lineno) if not test.examples: - self._out('WARNING: no examples in doctest block at ' - + filename + ', line %s\n' % code[0].lineno) continue for example in test.examples: # apply directive's comparison options @@ -320,7 +327,7 @@ Doctest summary # DocTest.__init__ copies the globs namespace, which we don't want test.globs = ns # also don't clear the globs namespace after running the doctest - self.test_runner.run(test, out=self._out, clear_globs=False) + self.test_runner.run(test, out=self._warn_out, clear_globs=False) def setup(app):