@@ -51,6 +51,14 @@ a comma-separated list of group names.
5151 A setup code block. This code is not shown in the output for other builders,
5252 but executed before the doctests of the group(s) it belongs to.
5353
54+ .. rubric :: Options
55+
56+ .. rst:directive:option:: skipif: condition
57+ :type: text
58+
59+ Skip the directive if the python expression *condition* is True.
60+ See :ref:`skipif`.
61+
5462
5563 .. rst :directive :: .. testcleanup:: [group]
5664
@@ -59,6 +67,14 @@ a comma-separated list of group names.
5967
6068 .. versionadded :: 1.1
6169
70+ .. rubric :: Options
71+
72+ .. rst:directive:option:: skipif: condition
73+ :type: text
74+
75+ Skip the directive if the python expression *condition* is True.
76+ See :ref:`skipif`.
77+
6278
6379 .. rst :directive :: .. doctest:: [group]
6480
@@ -67,72 +83,97 @@ a comma-separated list of group names.
6783 default set of flags is specified by the :confval: `doctest_default_flags `
6884 configuration variable.
6985
70- This directive supports five options:
86+ .. rubric :: Options
87+
88+ .. rst:directive:option:: hide
89+
90+ Hide the doctest block in other builders. By default it is shown as a
91+ highlighted doctest block.
92+
93+ .. rst:directive:option:: options: doctest flags
94+ :type: comma separated list
95+
96+ A comma-separated list of doctest flags that apply to each example in the
97+ tests. (You still can give explicit flags per example, with doctest comments,
98+ but they will show up in other builders too.)
99+
100+ Alternatively, you can give inline doctest options, like in doctest::
71101
72- * `` hide ``, a flag option, hides the doctest block in other builders. By
73- default it is shown as a highlighted doctest block.
102+ >>> datetime.date.now() # doctest: +SKIP
103+ datetime.date(2008, 1, 1)
74104
75- * ``options ``, a string option, can be used to give a comma-separated list of
76- doctest flags that apply to each example in the tests. (You still can give
77- explicit flags per example, with doctest comments, but they will show up in
78- other builders too.)
105+ They will be respected when the test is run, but by default will be stripped from
106+ presentation output. You can prevent stripping using the option
107+ :rst:dir:`doctest:no-trim-doctest-flags`.
79108
80- * ``pyversion ``, a string option, can be used to specify the required Python
81- version for the example to be tested. For instance, in the following case
82- the example will be tested only for Python versions greater than 3.12::
109+ .. rst:directive:option:: pyversion
110+ :type: text
111+
112+ Specify the required Python version for the example to be tested. For instance,
113+ in the following case the example will be tested only for Python versions greater
114+ than 3.12::
83115
84116 .. doctest::
85117 :pyversion: > 3.12
86118
87- The following operands are supported:
88-
89- * ``~= ``: Compatible release clause
90- * ``== ``: Version matching clause
91- * ``!= ``: Version exclusion clause
92- * ``<= ``, ``>= ``: Inclusive ordered comparison clause
93- * ``< ``, ``> ``: Exclusive ordered comparison clause
94- * ``=== ``: Arbitrary equality clause.
119+ The following operands are supported:
95120
96- ``pyversion `` option is followed :pep: `PEP-440: Version Specifiers
97- <440#version-specifiers >`.
121+ * ``~=``: Compatible release clause
122+ * ``==``: Version matching clause
123+ * ``!=``: Version exclusion clause
124+ * ``<=``, ``>=``: Inclusive ordered comparison clause
125+ * ``<``, ``>``: Exclusive ordered comparison clause
126+ * ``===``: Arbitrary equality clause.
98127
99- .. versionadded :: 1.6
128+ ``pyversion`` option is followed :pep:`PEP-440: Version Specifiers
129+ <440#version-specifiers>`.
100130
101- .. versionchanged :: 1.7
131+ .. versionadded :: 1.6
102132
103- Supported PEP-440 operands and notations
133+ .. versionchanged:: 1.7
104134
105- * ``trim-doctest-flags `` and ``no-trim-doctest-flags ``, a flag option,
106- doctest flags (comments looking like ``# doctest: FLAG, ... ``) at the
107- ends of lines and ``<BLANKLINE> `` markers are removed (or not removed)
108- individually. Default is ``trim-doctest-flags ``.
135+ Supported PEP-440 operands and notations
109136
110- Note that like with standard doctests, you have to use ``<BLANKLINE> `` to
111- signal a blank line in the expected output. The ``<BLANKLINE> `` is removed
112- when building presentation output (HTML, LaTeX etc.).
137+ .. rst:directive:option:: trim-doctest-flags
138+ .. rst:directive:option:: no-trim-doctest-flags
113139
114- Also, you can give inline doctest options, like in doctest::
140+ Whether to trim remove doctest flags (comments looking like
141+ ``# doctest: FLAG, ...``) at the ends of lines and ``<BLANKLINE>`` markers
142+ individually. Default is ``trim-doctest-flags``.
115143
116- >>> datetime.date.now() # doctest: +SKIP
117- datetime.date(2008, 1, 1)
144+ Note that like with standard doctests, you have to use ``<BLANKLINE>`` to
145+ signal a blank line in the expected output. The ``<BLANKLINE>`` is removed
146+ when building presentation output (HTML, LaTeX etc.).
118147
119- They will be respected when the test is run, but stripped from presentation
120- output.
148+ .. rst:directive:option:: skipif: condition
149+ :type: text
121150
151+ Skip the directive if the python expression *condition* is True.
152+ See :ref:`skipif`.
122153
123154 .. rst :directive :: .. testcode:: [group]
124155
125156 A code block for a code-output-style test.
126157
127- This directive supports three options:
158+ .. rubric :: Options
159+
160+ .. rst:directive:option:: hide
161+
162+ Hide the code block in other builders. By default it is shown as a
163+ highlighted code block.
164+
165+ .. rst:directive:option:: trim-doctest-flags
166+ .. rst:directive:option:: no-trim-doctest-flags
167+
168+ Whether to trim remove doctest flags (comments looking like
169+ ``# doctest: FLAG, ...``) at the ends of lines and ``<BLANKLINE>`` markers
170+ individually. Default is ``trim-doctest-flags``.
128171
129- * `` hide ``, a flag option, hides the code block in other builders. By
130- default it is shown as a highlighted code block.
172+ .. rst:directive: option:: skipif: condition
173+ :type: text
131174
132- * ``trim-doctest-flags `` and ``no-trim-doctest-flags ``, a flag option,
133- doctest flags (comments looking like ``# doctest: FLAG, ... ``) at the
134- ends of lines and ``<BLANKLINE> `` markers are removed (or not removed)
135- individually. Default is ``trim-doctest-flags ``.
175+ Skip the directive if the python expression *condition* is True.
176+ See :ref:`skipif`.
136177
137178 .. note ::
138179
@@ -159,18 +200,28 @@ a comma-separated list of group names.
159200 The corresponding output, or the exception message, for the last
160201 :rst:dir: `testcode ` block.
161202
162- This directive supports four options:
203+ .. rst: directive:option:: hide
163204
164- * `` hide ``, a flag option, hides the output block in other builders. By
165- default it is shown as a literal block without highlighting .
205+ Hide the doctest block in other builders. By default it is shown as a
206+ highlighted doctest block.
166207
167- * `` options ``, a string option, can be used to give doctest flags
168- (comma-separated) just like in normal doctest blocks.
208+ .. rst:directive: option:: options: doctest flags
209+ :type: comma separated list
169210
170- * ``trim-doctest-flags `` and ``no-trim-doctest-flags ``, a flag option,
171- doctest flags (comments looking like ``# doctest: FLAG, ... ``) at the
172- ends of lines and ``<BLANKLINE> `` markers are removed (or not removed)
173- individually. Default is ``trim-doctest-flags ``.
211+ A comma-separated list of doctest flags.
212+
213+ .. rst:directive:option:: trim-doctest-flags
214+ .. rst:directive:option:: no-trim-doctest-flags
215+
216+ Whether to trim remove doctest flags (comments looking like
217+ ``# doctest: FLAG, ...``) at the ends of lines and ``<BLANKLINE>`` markers
218+ individually. Default is ``trim-doctest-flags``.
219+
220+ .. rst:directive:option:: skipif: condition
221+ :type: text
222+
223+ Skip the directive if the python expression *condition* is True.
224+ See :ref:`skipif`.
174225
175226 Example::
176227
@@ -217,6 +268,8 @@ The following is an example for the usage of the directives. The test via
217268 This parrot wouldn't voom if you put 3000 volts through it!
218269
219270
271+ .. _skipif :
272+
220273Skipping tests conditionally
221274----------------------------
222275
0 commit comments