|
10 | 10 | import tempfile |
11 | 11 | from unittest import TestCase, skipUnless, skipIf |
12 | 12 | from unittest.mock import patch |
13 | | -from test.support import force_not_colorized, make_clean_env |
| 13 | +from test.support import force_not_colorized, make_clean_env, patch_list |
14 | 14 | from test.support import SHORT_TIMEOUT |
15 | 15 | from test.support.import_helper import import_module |
16 | 16 | from test.support.os_helper import unlink |
@@ -904,7 +904,17 @@ def prepare_reader(self, events, namespace): |
904 | 904 | reader = ReadlineAlikeReader(console=console, config=config) |
905 | 905 | return reader |
906 | 906 |
|
| 907 | + @patch_list(sys.meta_path) |
907 | 908 | def test_import_completions(self): |
| 909 | + from importlib.machinery import BuiltinImporter |
| 910 | + # Remove all importers except for the builtin one |
| 911 | + # to prevent searching anything but the builtin modules. |
| 912 | + # This makes the test more reliable in case there are |
| 913 | + # other user packages/scripts on PYTHONPATH which can |
| 914 | + # intefere with the completions. |
| 915 | + sys.meta_path = [finder for finder in sys.meta_path |
| 916 | + if isinstance(finder, BuiltinImporter)] |
| 917 | + |
908 | 918 | cases = ( |
909 | 919 | ("import path\t\n", "import pathlib"), |
910 | 920 | ("import importlib.\t\tres\t\n", "import importlib.resources"), |
|
0 commit comments