Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d427153

Browse files
lpsingertacaswell
authored andcommitted
TST: Add unit test to catch recurrences of #20822, #20855
1 parent 627dbd6 commit d427153

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/matplotlib/tests/test_getattr.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from importlib import import_module
2+
from pkgutil import walk_packages
3+
4+
import matplotlib
5+
import pytest
6+
7+
# Get the names of all matplotlib submodules, except for the unit tests.
8+
module_names = [m.name for m in walk_packages(path=matplotlib.__path__,
9+
prefix=f'{matplotlib.__name__}.')
10+
if not m.name.startswith(__package__)]
11+
12+
13+
@pytest.mark.parametrize('module_name', module_names)
14+
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
15+
def test_getattr(module_name):
16+
"""
17+
Test that __getattr__ methods raise AttributeError for unknown keys.
18+
See #20822, #20855.
19+
"""
20+
try:
21+
module = import_module(module_name)
22+
except (ImportError, RuntimeError) as e:
23+
# Skip modules that cannot be imported due to missing dependencies
24+
pytest.skip(f'Cannot import {module_name} due to {e}')
25+
26+
key = 'THIS_SYMBOL_SHOULD_NOT_EXIST'
27+
if hasattr(module, key):
28+
delattr(module, key)

0 commit comments

Comments
 (0)