Skip to content

Commit 9c89a67

Browse files
authored
Merge pull request #316 from mkelley/test-multiple-directives-2026.01
Test multiple directives
2 parents 6d325b0 + 4f624dd commit 9c89a67

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
1.7.0 (unreleased)
22
==================
33

4+
- Fixing crashing sphinx builds where multiple directives are used with the
5+
first one expecting content. The order of the directives used does not
6+
matter after this fix. [#316]
7+
48
- Versions of Python <3.10 and pytest<7 are no longer supported. [#313]
59

610
1.6.0 (2025-11-20)

pytest_doctestplus/sphinx/doctestplus.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,26 @@
1010
tests.
1111
"""
1212
import re
13-
from docutils.nodes import literal_block
1413
from docutils.parsers.rst import Directive
15-
14+
from sphinx.util.docutils import SphinxDirective
1615

1716
class NoRunDirective(Directive):
1817
def run(self):
1918
# Simply do not add any content when this directive is encountered
2019
return []
2120

2221

23-
class DoctestSkipDirective(Directive):
22+
class DoctestSkipDirective(SphinxDirective):
2423
has_content = True
2524

2625
def run(self):
2726
# Check if there is any valid argument, and skip it. Currently only
2827
# 'win32' is supported.
29-
if re.match('win32', self.content[0]):
28+
if len(self.content) > 0 and re.match("win32", self.content[0]):
3029
self.content = self.content[2:]
31-
code = '\n'.join(self.content)
32-
return [literal_block(code, code)]
3330

31+
nodes = self.parse_content_to_nodes()
32+
return nodes
3433

3534
class DoctestOmitDirective(NoRunDirective):
3635
has_content = True

tests/docs/skip_some.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,41 @@ Code in doctest should run only if version condition is satisfied:
102102
.. doctest-requires:: pytest>=1.0 pytest>=2.0
103103

104104
>>> import pytest
105+
106+
107+
Combined Directives
108+
===================
109+
110+
111+
Marking code with two directives:
112+
113+
.. deprecated:: 1.0
114+
.. doctest-requires:: numpy<=0.1
115+
116+
>>> 1 + 3
117+
2
118+
119+
120+
The order should not matter:
121+
122+
.. doctest-requires:: numpy<=0.1
123+
.. deprecated:: 1.0
124+
125+
>>> 1 + 3
126+
2
127+
128+
Try two doctestplus directives:
129+
130+
.. doctest-requires:: sys
131+
.. doctest-skip::
132+
133+
>>> 1 + 3
134+
2
135+
136+
Switch the order and it should still not run:
137+
138+
.. doctest-skip::
139+
.. doctest-requires:: sys
140+
141+
>>> 1 + 3
142+
2

0 commit comments

Comments
 (0)