Skip to content

Commit 1471729

Browse files
Use config value as default doctest group name (#13859)
1 parent db46f0b commit 1471729

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ Bugs fixed
116116
* #10785: Autodoc: Allow type aliases defined in the project to be properly
117117
cross-referenced when used as type annotations. This makes it possible
118118
for objects documented as ``:py:data:`` to be hyperlinked in function signatures.
119+
* #13858: doctest: doctest blocks are now correctly added to a group defined by the
120+
configuration variable ``doctest_test_doctest_blocks``.
121+
119122

120123
Testing
121124
-------

sphinx/ext/doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def test_doc(self, docname: str, doctree: Node) -> bool:
460460
lineno=line_number, # type: ignore[arg-type]
461461
options=node.get('options'), # type: ignore[attr-defined]
462462
)
463-
node_groups = node.get('groups', ['default']) # type: ignore[attr-defined]
463+
node_groups = node.get('groups', [self.config.doctest_test_doctest_blocks]) # type: ignore[attr-defined]
464464
if '*' in node_groups:
465465
add_to_all_groups.append(code)
466466
continue

tests/test_extensions/test_ext_doctest.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,29 @@ def test_fail_fast(app, fail_fast, capsys):
167167
else:
168168
assert 'Doctest summary\n' in written
169169
assert '2 failures in tests' in written
170+
171+
172+
@pytest.mark.sphinx('doctest', testroot='ext-doctest-with-autodoc')
173+
@pytest.mark.parametrize(
174+
('test_doctest_blocks', 'group_name'),
175+
[(None, 'default'), ('CustomGroupName', 'CustomGroupName')],
176+
)
177+
def test_doctest_block_group_name(app, test_doctest_blocks, group_name, capfd):
178+
if test_doctest_blocks is not None:
179+
app.config.doctest_test_doctest_blocks = test_doctest_blocks
180+
181+
# Patch builder to get a copy of the output
182+
written = []
183+
app.builder._warn_out = written.append
184+
app.build(force_all=True)
185+
186+
failures = [
187+
line.replace(os.sep, '/')
188+
for line in '\n'.join(written).splitlines()
189+
if line.startswith('File')
190+
]
191+
192+
assert f'File "dir/inner.rst", line 1, in {group_name}' in failures
193+
assert f'File "dir/bar.py", line ?, in {group_name}' in failures
194+
assert f'File "foo.py", line ?, in {group_name}' in failures
195+
assert f'File "index.rst", line 4, in {group_name}' in failures

0 commit comments

Comments
 (0)