Repository: scikit-learn-contrib/imbalanced-learn (language: python)

Issue:
Python 3.13: Two tests from test_docstring.py are failing
Fedora is preparing for Python 3.13. Two tests are currently failing when imbalanced-learn is built with Python 3.13.0a5. Python is being updated as new pre-releases become available and packages are re-tested.

Error log:

```python
=================================== FAILURES ===================================
_ test_docstring_inject[func-A function.\n\n    Parameters\n    ----------\n    xxx\n\n    yyy\n    ] _

obj = <function func at 0x7f092abffce0>
obj_docstring = 'A function.\n\n    Parameters\n    ----------\n    xxx\n\n    yyy\n    '

    @pytest.mark.parametrize(
        "obj, obj_docstring", [(func, func_docstring), (cls, cls_docstring)]
    )
    def test_docstring_inject(obj, obj_docstring):
        obj_injected_docstring = Substitution(param_1="xxx", param_2="yyy")(obj)
>       assert obj_injected_docstring.__doc__ == obj_docstring
E       AssertionError: assert 'A function.\n\nParameters\n----------\nxxx\n\nyyy\n' == 'A function.\n\n    Parameters\n    ----------\n    xxx\n\n    yyy\n    '
E           A function.
E           
E         -     Parameters
E         ? ----
E         + Parameters
E         -     ----------
E         ? ----
E         + ----------
E         -     xxx
E         + xxx
E           
E         + yyy
E         -     yyy
E         -

imblearn/utils/tests/test_docstring.py:63: AssertionError
_ test_docstring_inject[cls-A class.\n\n    Parameters\n    ----------\n    xxx\n\n    yyy\n    ] _

obj = <class 'imblearn.utils.tests.test_docstring.cls'>
obj_docstring = 'A class.\n\n    Parameters\n    ----------\n    xxx\n\n    yyy\n    '

    @pytest.mark.parametrize(
        "obj, obj_docstring", [(func, func_docstring), (cls, cls_docstring)]
    )
    def test_docstring_inject(obj, obj_docstring):
        obj_injected_docstring = Substitution(param_1="xxx", param_2="yyy")(obj)
>       assert obj_injected_docstring.__doc__ == obj_docstring
E       AssertionError: assert 'A class.\n\nParameters\n----------\nxxx\n\nyyy\n' == 'A class.\n\n    Parameters\n    ----------\n    xxx\n\n    yyy\n    '
E           A class.
E           
E         -     Parameters
E         ? ----
E         + Parameters
E         -     ----------
E         ? ----
E         + ----------
E         -     xxx
E         + xxx
E           
E         + yyy
E         -     yyy
E         -

imblearn/utils/tests/test_docstring.py:63: AssertionError
```


Discussion / hints:
This is most likely due to:

> Compiler now strip indents from docstrings. This will reduce the size of [bytecode cache](https://docs.python.org/3.13/glossary.html#term-bytecode) (e.g. .pyc file). For example, cache file size for sqlalchemy.orm.session in SQLAlchemy 2.0 is reduced by about 5%. This change will affect tools using docstrings, like [doctest](https://docs.python.org/3.13/library/doctest.html#module-doctest). (Contributed by Inada Naoki in [gh-81283](https://github.com/python/cpython/issues/81283).)

as documented in the [release notes](https://docs.python.org/3.13/whatsnew/3.13.html#other-language-changes).
Thanks. We probably want to have our tests insensitive to this particular behaviour. I'll make a fix for that.

Fix patch:
diff --git a/doc/whats_new/v0.12.rst b/doc/whats_new/v0.12.rst
index bc707ae8c..741b9173e 100644
--- a/doc/whats_new/v0.12.rst
+++ b/doc/whats_new/v0.12.rst
@@ -19,7 +19,13 @@ Compatibility
 .............
 
 - Do not use `distutils` in tests due to deprecation.
-  :pr:`1065` by :user:`Michael R. Crusoe <mr-c>`
+  :pr:`1065` by :user:`Michael R. Crusoe <mr-c>`.
+
+- Fix the scikit-learn import in tests to be compatible with version 1.4.1.post1.
+  :pr:`1073` by :user:`Guillaume Lemaitre <glemaitre>`.
+
+- Fix test to be compatible with Python 3.13.
+  :pr:`1073` by :user:`Guillaume Lemaitre <glemaitre>`.
 
 Version 0.12.0
 ==============
diff --git a/setup.py b/setup.py
index f7856666a..5e26c3480 100755
--- a/setup.py
+++ b/setup.py
@@ -49,10 +49,10 @@
     "Operating System :: POSIX",
     "Operating System :: Unix",
     "Operating System :: MacOS",
-    "Programming Language :: Python :: 3.8",
     "Programming Language :: Python :: 3.9",
     "Programming Language :: Python :: 3.10",
     "Programming Language :: Python :: 3.11",
+    "Programming Language :: Python :: 3.12",
 ]
 PYTHON_REQUIRES = ">=3.8"
 INSTALL_REQUIRES = (min_deps.tag_to_packages["install"],)


Test patch:
diff --git a/imblearn/utils/tests/test_docstring.py b/imblearn/utils/tests/test_docstring.py
index 0109fdb31..133701f8d 100644
--- a/imblearn/utils/tests/test_docstring.py
+++ b/imblearn/utils/tests/test_docstring.py
@@ -3,11 +3,23 @@
 # Authors: Guillaume Lemaitre <g.lemaitre58@gmail.com>
 # License: MIT
 
+import sys
+import textwrap
+
 import pytest
 
 from imblearn.utils import Substitution
 from imblearn.utils._docstring import _n_jobs_docstring, _random_state_docstring
 
+
+def _dedent_docstring(docstring):
+    """Compatibility with Python 3.13+.
+
+    xref: https://github.com/python/cpython/issues/81283
+    """
+    return "\n".join([textwrap.dedent(line) for line in docstring.split("\n")])
+
+
 func_docstring = """A function.
 
     Parameters
@@ -55,6 +67,11 @@ def __init__(self, param_1, param_2):
         self.param_2 = param_2
 
 
+if sys.version_info.minor == "13":
+    func_docstring = _dedent_docstring(func_docstring)
+    cls_docstring = _dedent_docstring(cls_docstring)
+
+
 @pytest.mark.parametrize(
     "obj, obj_docstring", [(func, func_docstring), (cls, cls_docstring)]
 )