diff --git a/CHANGES.rst b/CHANGES.rst index b0ee624..3d508a6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,10 @@ 1.7.0 (unreleased) ================== +- Fixing crashing sphinx builds where multiple directives are used with the + first one expecting content. The order of the directives used does not + matter after this fix. [#316] + - Versions of Python <3.10 and pytest<7 are no longer supported. [#313] 1.6.0 (2025-11-20) diff --git a/pytest_doctestplus/sphinx/doctestplus.py b/pytest_doctestplus/sphinx/doctestplus.py index 00b80f7..03ba7fd 100644 --- a/pytest_doctestplus/sphinx/doctestplus.py +++ b/pytest_doctestplus/sphinx/doctestplus.py @@ -10,9 +10,8 @@ tests. """ import re -from docutils.nodes import literal_block from docutils.parsers.rst import Directive - +from sphinx.util.docutils import SphinxDirective class NoRunDirective(Directive): def run(self): @@ -20,17 +19,17 @@ def run(self): return [] -class DoctestSkipDirective(Directive): +class DoctestSkipDirective(SphinxDirective): has_content = True def run(self): # Check if there is any valid argument, and skip it. Currently only # 'win32' is supported. - if re.match('win32', self.content[0]): + if len(self.content) > 0 and re.match("win32", self.content[0]): self.content = self.content[2:] - code = '\n'.join(self.content) - return [literal_block(code, code)] + nodes = self.parse_content_to_nodes() + return nodes class DoctestOmitDirective(NoRunDirective): has_content = True diff --git a/tests/docs/skip_some.rst b/tests/docs/skip_some.rst index deceff0..2dd68fa 100644 --- a/tests/docs/skip_some.rst +++ b/tests/docs/skip_some.rst @@ -102,3 +102,41 @@ Code in doctest should run only if version condition is satisfied: .. doctest-requires:: pytest>=1.0 pytest>=2.0 >>> import pytest + + +Combined Directives +=================== + + +Marking code with two directives: + +.. deprecated:: 1.0 +.. doctest-requires:: numpy<=0.1 + + >>> 1 + 3 + 2 + + +The order should not matter: + +.. doctest-requires:: numpy<=0.1 +.. deprecated:: 1.0 + + >>> 1 + 3 + 2 + +Try two doctestplus directives: + +.. doctest-requires:: sys +.. doctest-skip:: + + >>> 1 + 3 + 2 + +Switch the order and it should still not run: + +.. doctest-skip:: +.. doctest-requires:: sys + + >>> 1 + 3 + 2