File fix.patch of Package python-matplotlib
From e8ee2799f64db1160efce705cf6965a6e76884d3 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Tue, 9 Sep 2025 02:22:26 -0400
Subject: [PATCH] TST: Run test_getattr for backends in a subprocess
For example, GTK3 and GTK4 conflict, and which one is tested depends on
which one loads first. Running in a subprocess ensures that both work,
but we only do that for backends as adding ~100 more subprocesses is
overkill.
---
lib/matplotlib/tests/test_getattr.py | 59 +++++++++++++++++++++-------
1 file changed, 45 insertions(+), 14 deletions(-)
diff --git a/lib/matplotlib/tests/test_getattr.py b/lib/matplotlib/tests/test_getattr.py
index f0f5823600ca..fe302220067a 100644
--- a/lib/matplotlib/tests/test_getattr.py
+++ b/lib/matplotlib/tests/test_getattr.py
@@ -1,25 +1,29 @@
from importlib import import_module
from pkgutil import walk_packages
+import sys
+import warnings
-import matplotlib
import pytest
+import matplotlib
+from matplotlib.testing import is_ci_environment, subprocess_run_helper
+
# Get the names of all matplotlib submodules,
# except for the unit tests and private modules.
-module_names = [
- m.name
- for m in walk_packages(
- path=matplotlib.__path__, prefix=f'{matplotlib.__name__}.'
- )
- if not m.name.startswith(__package__)
- and not any(x.startswith('_') for x in m.name.split('.'))
-]
+module_names = []
+backend_module_names = []
+for m in walk_packages(path=matplotlib.__path__, prefix=f'{matplotlib.__name__}.'):
+ if m.name.startswith(__package__):
+ continue
+ if any(x.startswith('_') for x in m.name.split('.')):
+ continue
+ if 'backends.backend_' in m.name:
+ backend_module_names.append(m.name)
+ else:
+ module_names.append(m.name)
-@pytest.mark.parametrize('module_name', module_names)
-@pytest.mark.filterwarnings('ignore::DeprecationWarning')
-@pytest.mark.filterwarnings('ignore::ImportWarning')
-def test_getattr(module_name):
+def _test_getattr(module_name, use_pytest=True):
"""
Test that __getattr__ methods raise AttributeError for unknown keys.
See #20822, #20855.
@@ -28,8 +32,35 @@ def test_getattr(module_name):
module = import_module(module_name)
except (ImportError, RuntimeError, OSError) as e:
# Skip modules that cannot be imported due to missing dependencies
- pytest.skip(f'Cannot import {module_name} due to {e}')
+ if use_pytest:
+ pytest.skip(f'Cannot import {module_name} due to {e}')
+ else:
+ print(f'SKIP: Cannot import {module_name} due to {e}')
+ return
key = 'THIS_SYMBOL_SHOULD_NOT_EXIST'
if hasattr(module, key):
delattr(module, key)
+
+
+@pytest.mark.parametrize('module_name', module_names)
+@pytest.mark.filterwarnings('ignore::DeprecationWarning')
+@pytest.mark.filterwarnings('ignore::ImportWarning')
+def test_getattr(module_name):
+ _test_getattr(module_name)
+
+
+def _test_module_getattr():
+ warnings.filterwarnings('ignore', category=DeprecationWarning)
+ warnings.filterwarnings('ignore', category=ImportWarning)
+ module_name = sys.argv[1]
+ _test_getattr(module_name, use_pytest=False)
+
+
+@pytest.mark.parametrize('module_name', backend_module_names)
+def test_backend_getattr(module_name):
+ proc = subprocess_run_helper(_test_module_getattr, module_name,
+ timeout=120 if is_ci_environment() else 20)
+ if 'SKIP: ' in proc.stdout:
+ pytest.skip(proc.stdout.removeprefix('SKIP: '))
+ print(proc.stdout)