ci: fix issue with latest sphinx (#20661)

This commit is contained in:
Massimiliano Culpo 2021-01-04 22:10:49 +01:00 committed by GitHub
parent 11dd7ffad6
commit cfd0ff52d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -118,7 +118,11 @@ def __init__(self, namespace):
def __getattr__(self, name):
"""Getattr lazily loads modules if they're not already loaded."""
submodule = self.__package__ + '.' + name
setattr(self, name, __import__(submodule))
try:
setattr(self, name, __import__(submodule))
except ImportError:
msg = "'{0}' object has no attribute {1}"
raise AttributeError(msg.format(type(self), name))
return getattr(self, name)

View file

@ -67,3 +67,15 @@ def test_repo_invisibles(mutable_mock_repo, extra_repo):
with open(os.path.join(extra_repo.root, 'packages', '.invisible'), 'w'):
pass
extra_repo.all_package_names()
@pytest.mark.parametrize('attr_name,exists', [
('cmake', True),
('__sphinx_mock__', False)
])
@pytest.mark.regression('20661')
def test_namespace_hasattr(attr_name, exists, mutable_mock_repo):
# Check that we don't fail on 'hasattr' checks because
# of a custom __getattr__ implementation
nms = spack.repo.SpackNamespace('spack.pkg.builtin.mock')
assert hasattr(nms, attr_name) == exists