summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2023-01-10 22:39:19 +0000
committerGitHub <noreply@github.com>2023-01-10 22:39:19 +0000
commit22dacffd5c6be242125311adaac610f95dd094e3 (patch)
tree1a05307e33ca665bf5690ed0b64b03afee4fc870 /tests
parentfe058bff95745371df5796286d33677c21137847 (diff)
downloadastroid-git-22dacffd5c6be242125311adaac610f95dd094e3.tar.gz
Fix a regression in 2.13.2 where a ``RunTimeError`` could be raised unexpectedly (#1959) (#1962)
* Add a unit test for broken __getattr__ in extension modules Co-authored-by: Florian Bruhin <me@the-compiler.org> Closes #1958 (cherry picked from commit 9eb8c47ddb6b48e14dbdb87bb1b02fcb580cb20d) Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/testdata/python3/data/fake_module_with_broken_getattr.py7
-rw-r--r--tests/unittest_raw_building.py16
2 files changed, 22 insertions, 1 deletions
diff --git a/tests/testdata/python3/data/fake_module_with_broken_getattr.py b/tests/testdata/python3/data/fake_module_with_broken_getattr.py
new file mode 100644
index 00000000..e860928e
--- /dev/null
+++ b/tests/testdata/python3/data/fake_module_with_broken_getattr.py
@@ -0,0 +1,7 @@
+class Broken:
+
+ def __getattr__(self, name):
+ raise Exception("boom")
+
+
+broken = Broken()
diff --git a/tests/unittest_raw_building.py b/tests/unittest_raw_building.py
index 59bd6ce1..64c22727 100644
--- a/tests/unittest_raw_building.py
+++ b/tests/unittest_raw_building.py
@@ -1,3 +1,9 @@
+"""
+'tests.testdata.python3.data.fake_module_with_warnings' and
+'tests.testdata.python3.data.fake_module_with_warnings' are fake modules
+to simulate issues in unittest below
+"""
+
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
@@ -8,7 +14,7 @@ import unittest
import _io
import pytest
-# A fake module to simulate pandas in unittest below
+import tests.testdata.python3.data.fake_module_with_broken_getattr as fm_getattr
import tests.testdata.python3.data.fake_module_with_warnings as fm
from astroid.builder import AstroidBuilder
from astroid.const import IS_PYPY
@@ -102,6 +108,14 @@ class RawBuildingTC(unittest.TestCase):
# This should not raise an exception
AstroidBuilder().module_build(m, "test")
+ def test_module_object_with_broken_getattr(self) -> None:
+ # Tests https://github.com/PyCQA/astroid/issues/1958
+ # When astroid deep inspection of modules raises
+ # errors when using hasattr().
+
+ # This should not raise an exception
+ AstroidBuilder().inspect_build(fm_getattr, "test")
+
if __name__ == "__main__":
unittest.main()