File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments