Repository: nilearn/nilearn

Issue:
test error for order of printed argument with python 3.11
See in a few runs of CI

For [example](https://github.com/nilearn/nilearn/actions/runs/5244068680/jobs/9469564671?pr=3742#step:8:14623)

```
 FAILED nilearn/plotting/tests/test_matrix_plotting.py::test_sanitize_reorder_error[None] - AssertionError: Regex pattern did not match.
 Regex: "Parameter reorder needs to be one of {False, True, 'complete', 'single', 'average'}"
 Input: "Parameter reorder needs to be one of {False, True, 'single', 'complete', 'average'}."
FAILED nilearn/plotting/tests/test_matrix_plotting.py::test_sanitize_reorder_error[foo] - AssertionError: Regex pattern did not match.
 Regex: "Parameter reorder needs to be one of {False, True, 'complete', 'single', 'average'}"
 Input: "Parameter reorder needs to be one of {False, True, 'single', 'complete', 'average'}."
FAILED nilearn/plotting/tests/test_matrix_plotting.py::test_sanitize_reorder_error[2] - AssertionError: Regex pattern did not match.
 Regex: "Parameter reorder needs to be one of {False, True, 'complete', 'single', 'average'}"
 Input: "Parameter reorder needs to be one of {False, True, 'single', 'complete', 'average'}."
= 3 failed, 2587 passed, 7 skipped, 2 xfailed, 1311 warnings in 1693.15s (0:28:13) =
```


Discussion:
@ymzayek : I will have a look at this. 

Resolving patch:
diff --git a/nilearn/plotting/matrix_plotting.py b/nilearn/plotting/matrix_plotting.py
--- a/nilearn/plotting/matrix_plotting.py
+++ b/nilearn/plotting/matrix_plotting.py
@@ -100,8 +100,15 @@ def _sanitize_reorder(reorder):
     """Help for plot_matrix."""
     VALID_REORDER_ARGS = {True, False, 'single', 'complete', 'average'}
     if reorder not in VALID_REORDER_ARGS:
+        param_to_print = []
+        for item in VALID_REORDER_ARGS:
+            if isinstance(item, str):
+                param_to_print.append(f'"{item}"')
+            else:
+                param_to_print.append(str(item))
         raise ValueError(
-            f"Parameter reorder needs to be one of {VALID_REORDER_ARGS}.")
+            f"Parameter reorder needs to be one of:\n{', '.join(param_to_print)}."
+        )
     reorder = 'average' if reorder is True else reorder
     return reorder
 


Test patch:
diff --git a/nilearn/plotting/tests/test_matrix_plotting.py b/nilearn/plotting/tests/test_matrix_plotting.py
--- a/nilearn/plotting/tests/test_matrix_plotting.py
+++ b/nilearn/plotting/tests/test_matrix_plotting.py
@@ -88,9 +88,15 @@ def test_sanitize_reorder(reorder):
 @pytest.mark.parametrize("reorder", [None, "foo", 2])
 def test_sanitize_reorder_error(reorder):
     from ..matrix_plotting import _sanitize_reorder
+    param_to_print = []
+    for item in VALID_REORDER_VALUES:
+        if isinstance(item, str):
+            param_to_print.append(f'"{item}"')
+        else:
+            param_to_print.append(str(item))
     with pytest.raises(ValueError,
-                       match=("Parameter reorder needs to be "
-                              f"one of {VALID_REORDER_VALUES}")):
+                       match=("Parameter reorder needs to be one of:\n"
+                              f"{', '.join(param_to_print)}.")):
         _sanitize_reorder(reorder)