diff options
author | Massimiliano Culpo <massimiliano.culpo@gmail.com> | 2021-01-04 22:10:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-04 22:10:49 +0100 |
commit | cfd0ff52d16fca8e71f08595cc961529e9ac360a (patch) | |
tree | c0aa7189ca05baba1eb49edb22dbd16548c2d671 | |
parent | 11dd7ffad631b8bf1665605db75b7c1b8e9eddcb (diff) | |
download | spack-cfd0ff52d16fca8e71f08595cc961529e9ac360a.tar.gz spack-cfd0ff52d16fca8e71f08595cc961529e9ac360a.tar.bz2 spack-cfd0ff52d16fca8e71f08595cc961529e9ac360a.tar.xz spack-cfd0ff52d16fca8e71f08595cc961529e9ac360a.zip |
ci: fix issue with latest sphinx (#20661)
-rw-r--r-- | lib/spack/spack/repo.py | 6 | ||||
-rw-r--r-- | lib/spack/spack/test/repo.py | 12 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py index a2ebf9f53a..b735866321 100644 --- a/lib/spack/spack/repo.py +++ b/lib/spack/spack/repo.py @@ -118,7 +118,11 @@ class SpackNamespace(types.ModuleType): 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) diff --git a/lib/spack/spack/test/repo.py b/lib/spack/spack/test/repo.py index 1a4331af63..df3015500d 100644 --- a/lib/spack/spack/test/repo.py +++ b/lib/spack/spack/test/repo.py @@ -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 |