From 05b8e8baec9f81463f6fba7df286ddcadab614aa Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 15 Oct 2022 12:33:23 -0400 Subject: Prevent a crash when a module's ``__path__`` is missing --- tests/unittest_manager.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/unittest_manager.py b/tests/unittest_manager.py index 1c8a3fdc..2266e32a 100644 --- a/tests/unittest_manager.py +++ b/tests/unittest_manager.py @@ -9,6 +9,7 @@ import time import unittest from collections.abc import Iterator from contextlib import contextmanager +from unittest import mock import pytest @@ -144,6 +145,14 @@ class AstroidManagerTest( finally: astroid_module.__spec__ = original_spec + @mock.patch( + "astroid.interpreter._import.util._find_spec_from_path", + side_effect=AttributeError, + ) + def test_module_unexpectedly_missing_path(self, mocked) -> None: + """https://github.com/PyCQA/pylint/issues/7592""" + self.assertFalse(util.is_namespace("astroid")) + def test_module_unexpectedly_spec_is_none(self) -> None: astroid_module = sys.modules["astroid"] original_spec = astroid_module.__spec__ -- cgit v1.2.1