diff --git a/CHANGES b/CHANGES index 7c3e7b8dc..f764d138e 100644 --- a/CHANGES +++ b/CHANGES @@ -5,7 +5,8 @@ Changes in trunk placed selectable, and default to ``'default'``. * sphinx.ext.doctest: Replace in doctest blocks by - real blank lines for presentation output. + real blank lines for presentation output, and remove doctest + options given inline. * sphinx.environment: Move doctest_blocks out of block_quotes to support indented doctest blocks. diff --git a/doc/ext/doctest.rst b/doc/ext/doctest.rst index 1931a4472..9de6ba9e9 100644 --- a/doc/ext/doctest.rst +++ b/doc/ext/doctest.rst @@ -69,6 +69,14 @@ names. signal a blank line in the expected output. The ```` is removed when building presentation output (HTML, LaTeX etc.). + Also, you can give inline doctest options, like in doctest:: + + >>> datetime.date.now() # doctest: +SKIP + datetime.date(2008, 1, 1) + + They will be respected when the test is run, but stripped from presentation + output. + .. directive:: .. testcode:: [group] @@ -178,4 +186,6 @@ There are also these config values for customizing the doctest extension: special directive. Note though that you can't have blank lines in reST doctest blocks. They - will be interpreted as one block ending and another one starting. + will be interpreted as one block ending and another one starting. Also, + removal of ```` and ``# doctest:`` options only works in + :dir:`doctest` blocks. diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index a46a7a303..3b895688b 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -25,7 +25,7 @@ from sphinx.builder import Builder from sphinx.util.console import bold blankline_re = re.compile(r'^\s*', re.MULTILINE) - +doctestopt_re = re.compile(r'#\s*doctest:.+$', re.MULTILINE) # set up the necessary directives @@ -35,10 +35,15 @@ def test_directive(name, arguments, options, content, lineno, # so that our builder recognizes them, and the other builders are happy. code = '\n'.join(content) test = None - if name == 'doctest' and '' in code: - # convert s to ordinary blank lines for presentation - test = code - code = blankline_re.sub('', code) + if name == 'doctest': + if '' in code: + # convert s to ordinary blank lines for presentation + test = code + code = blankline_re.sub('', code) + if doctestopt_re.search(code): + if not test: + test = code + code = doctestopt_re.sub('', code) nodetype = nodes.literal_block if name == 'testsetup' or 'hide' in options: nodetype = nodes.comment