Skip to content

sphinx.ext.doctest config variable doctest_test_doctest_blocks is not respected #13858

@ludovicsteinbach

Description

@ludovicsteinbach

Describe the bug

The documentation for doctest_test_doctest_blocks claims that If this is a nonempty string, standard reStructuredText doctest blocks will be tested too. They will be assigned to the group name given..

It does not. Regardless of the configuration value, the doctest blocks are assigned to the default group.

How to Reproduce

index.rst

bug-demo documentation
======================

.. testsetup:: Custom

   from module import *

.. autoclass:: module.MyClass

conf.py

import sys
sys.path.append(".")

extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.doctest",
]

doctest_test_doctest_blocks = "Custom"

module.py


class MyClass:
    """
    MyClass docstring

    Examples
    --------
    >>> instance = MyClass("value")

    """
    def __init__(self, value: str):
        self._value = value

When running sphinx-build -M doctest, observe failure:

**********************************************************************                                                                                                                                                              
1 item had failures:
   1 of   1 in default
1 test in 1 item.
0 passed and 1 failed.
***Test Failed*** 1 failure.

Doctest summary
===============
    1 test
    1 failure in tests
    0 failures in setup code
    0 failures in cleanup code
build finished with problems.

Changing the ..testsetup directive group to default makes the build succeed, even though doctest_test_doctest_blocks specifies that doctest blocks should be added to a Custom group

Environment Information

Platform:              win32; (Windows-11-10.0.26100-SP0)
Python version:        3.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)])
Python implementation: CPython
Sphinx version:        8.2.3
Docutils version:      0.21.2
Jinja2 version:        3.1.6
Pygments version:      2.19.2

Sphinx extensions

extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.doctest",
]

Additional context

It seems to me that the configuration variable simply isn't wired through:

node_groups = node.get('groups', ['default']) # type: ignore[attr-defined]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions