diff --git a/CHANGES b/CHANGES index bf9d04a76..fbf1bae0a 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,7 @@ Features added * Add ``:caption:`` option for sphinx.ext.inheritance_diagram. * #894: Add ``lualatexpdf`` and ``xelatexpdf`` as a make target to build PDF using lualatex or xelatex +* #2471: Add config variable for default doctest flags. Bugs fixed ---------- diff --git a/doc/ext/doctest.rst b/doc/ext/doctest.rst index 9b1b4e6d4..f3086f398 100644 --- a/doc/ext/doctest.rst +++ b/doc/ext/doctest.rst @@ -56,12 +56,9 @@ names. .. rst:directive:: .. doctest:: [group] A doctest-style code block. You can use standard :mod:`doctest` flags for - controlling how actual output is compared with what you give as output. By - default, these options are enabled: ``ELLIPSIS`` (allowing you to put - ellipses in the expected output that match anything in the actual output), - ``IGNORE_EXCEPTION_DETAIL`` (not comparing tracebacks), - ``DONT_ACCEPT_TRUE_FOR_1`` (by default, doctest accepts "True" in the output - where "1" is given -- this is a relic of pre-Python 2.2 times). + controlling how actual output is compared with what you give as output. The + default set of flags is specified by the :confval:`doctest_default_flags` + configuration variable. This directive supports two options: @@ -176,6 +173,20 @@ The following is an example for the usage of the directives. The test via There are also these config values for customizing the doctest extension: +.. confval:: doctest_default_flags + + By default, these options are enabled: + + - ``ELLIPSIS``, allowing you to put ellipses in the expected output that + match anything in the actual output; + - ``IGNORE_EXCEPTION_DETAIL``, causing everything following the leftmost + colon and any module information in the exception name to be ignored; + - ``DONT_ACCEPT_TRUE_FOR_1``, rejecting "True" in the output where "1" is + given -- the default behavior of accepting this substitution is a relic of + pre-Python 2.2 times. + + .. versionadded:: 1.5 + .. confval:: doctest_path A list of directories that will be added to :data:`sys.path` when the doctest diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index 0f5241a19..244762b69 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -214,8 +214,7 @@ class DocTestBuilder(Builder): def init(self): # default options - self.opt = doctest.DONT_ACCEPT_TRUE_FOR_1 | doctest.ELLIPSIS | \ - doctest.IGNORE_EXCEPTION_DETAIL + self.opt = self.config.doctest_default_flags # HACK HACK HACK # doctest compiles its snippets with type 'single'. That is nice @@ -464,4 +463,8 @@ def setup(app): app.add_config_value('doctest_test_doctest_blocks', 'default', False) app.add_config_value('doctest_global_setup', '', False) app.add_config_value('doctest_global_cleanup', '', False) + app.add_config_value( + 'doctest_default_flags', + doctest.DONT_ACCEPT_TRUE_FOR_1 | doctest.ELLIPSIS | doctest.IGNORE_EXCEPTION_DETAIL, + False) return {'version': sphinx.__display_version__, 'parallel_read_safe': True}