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

Skip to content

TST: Add unit test to catch recurrences of #20822, #20855 #20856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/matplotlib/tests/test_getattr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from importlib import import_module
from pkgutil import walk_packages

import matplotlib
import pytest

# Get the names of all matplotlib submodules, except for the unit tests.
module_names = [m.name for m in walk_packages(path=matplotlib.__path__,
prefix=f'{matplotlib.__name__}.')
if not m.name.startswith(__package__)]


@pytest.mark.parametrize('module_name', module_names)
@pytest.mark.filterwarnings('ignore::DeprecationWarning')
def test_getattr(module_name):
"""
Test that __getattr__ methods raise AttributeError for unknown keys.
See #20822, #20855.
"""
try:
module = import_module(module_name)
except (ImportError, RuntimeError) as e:
# Skip modules that cannot be imported due to missing dependencies
pytest.skip(f'Cannot import {module_name} due to {e}')

key = 'THIS_SYMBOL_SHOULD_NOT_EXIST'
if hasattr(module, key):
delattr(module, key)