Skip to content

BUG: doccer: test_decorator fails with Python 3.13 due to dedented docstring constants #19572

@hroncok

Description

@hroncok

Describe your issue.

When I try to build scipy 1.11.3 in Fedora with Python 3.13.0a1+ I see the following test failure:

________________________________ test_decorator ________________________________
[gw1] linux -- Python 3.13.0 /usr/bin/python3

    @pytest.mark.skipif(DOCSTRINGS_STRIPPED, reason="docstrings stripped")
    def test_decorator():
        with suppress_warnings() as sup:
            sup.filter(category=DeprecationWarning)
            # with unindentation of parameters
            decorator = doccer.filldoc(doc_dict, True)
    
            @decorator
            def func():
                """ Docstring
                %(strtest3)s
                """
>           assert_equal(func.__doc__, """ Docstring
                Another test
                   with some indent
                """)
E           AssertionError: 
E           Items are not equal:
E            ACTUAL: 'Docstring\nAnother test\n   with some indent\n'
E            DESIRED: ' Docstring\n            Another test\n               with some indent\n            '

scipy/misc/tests/test_doccer.py:86: AssertionError

This is likely caused by python/cpython#81283 -- Automatically dedent docstring constants by default.

I tried to get around this by asserting the docstrings are equal to manual dostrings, e.g.:

        @decorator
        def func():
            """ Docstring
            %(strtest3)s
            """

        def expected():
            """ Docstring
            Another test
               with some indent
            """
        assert_equal(func.__doc__, expected.__doc__)

But I think the dosctring of the original function is dedented first and the substitution happens after; hence the results are not the same as dedented manually constructed docstrings.

I could add if sys.version around the expected value, but I am unsure if that is the proper fix. Before I submit a PR that makes changes to the test, I need to understand how we want this to behave on Python 3.13.

Reproducing Code Example

run the tests

Error message

see above

SciPy/NumPy/Python version and system information

I am no longer able to paste the command above. This is on scipy 1.11.3 with numpy 1.26.0 and Python built from the main branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedmaintenanceItems related to regular maintenance tasksscipy.misc

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions