From 534ea82659eb981d6abb13a39b86271d5223eebb Mon Sep 17 00:00:00 2001 From: "Michael S. P. Kelley" Date: Fri, 2 Jan 2026 08:50:50 -0500 Subject: [PATCH 1/4] Test marking code with two directives. --- tests/docs/skip_some.rst | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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 From c2ca08a47c136ede6865bc968a1a606446b31d38 Mon Sep 17 00:00:00 2001 From: "Michael S. P. Kelley" Date: Fri, 2 Jan 2026 08:52:02 -0500 Subject: [PATCH 2/4] Test for content before indexing. When there are two directives in series, the first one will not have any content. As a result, self.content[0] will raise an error. --- pytest_doctestplus/sphinx/doctestplus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_doctestplus/sphinx/doctestplus.py b/pytest_doctestplus/sphinx/doctestplus.py index 00b80f7..960a5a8 100644 --- a/pytest_doctestplus/sphinx/doctestplus.py +++ b/pytest_doctestplus/sphinx/doctestplus.py @@ -26,7 +26,7 @@ class DoctestSkipDirective(Directive): 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)] From fb5db0c4ec09474663cbea7bf50e2443081f8dd2 Mon Sep 17 00:00:00 2001 From: "Michael S. P. Kelley" Date: Fri, 2 Jan 2026 09:22:47 -0500 Subject: [PATCH 3/4] Avoid rendering empty blocks. DoctestSkipDirective inherits from SphinxDirective, which does not render empty blocks when content is empty. --- pytest_doctestplus/sphinx/doctestplus.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pytest_doctestplus/sphinx/doctestplus.py b/pytest_doctestplus/sphinx/doctestplus.py index 960a5a8..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,7 +19,7 @@ def run(self): return [] -class DoctestSkipDirective(Directive): +class DoctestSkipDirective(SphinxDirective): has_content = True def run(self): @@ -28,9 +27,9 @@ def run(self): # 'win32' is supported. 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 From 4f624dd9ccdc8a41f0b2a67ae451a0dd387c5775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brigitta=20Sip=C5=91cz?= Date: Wed, 7 Jan 2026 20:12:22 -0800 Subject: [PATCH 4/4] DOC: adding changelog --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) 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)