File tree Expand file tree Collapse file tree 3 files changed +47
-6
lines changed
pytest_doctestplus/sphinx Expand file tree Collapse file tree 3 files changed +47
-6
lines changed Original file line number Diff line number Diff line change 111.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
6101.6.0 (2025-11-20)
Original file line number Diff line number Diff line change 1010tests.
1111"""
1212import re
13- from docutils .nodes import literal_block
1413from docutils .parsers .rst import Directive
15-
14+ from sphinx . util . docutils import SphinxDirective
1615
1716class 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
3534class DoctestOmitDirective (NoRunDirective ):
3635 has_content = True
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments