Skip to content

Commit 8eb656f

Browse files
committed
Make the tests more robust
1 parent 3c13f86 commit 8eb656f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import tempfile
1111
from unittest import TestCase, skipUnless, skipIf
1212
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
1414
from test.support import SHORT_TIMEOUT
1515
from test.support.import_helper import import_module
1616
from test.support.os_helper import unlink
@@ -904,7 +904,17 @@ def prepare_reader(self, events, namespace):
904904
reader = ReadlineAlikeReader(console=console, config=config)
905905
return reader
906906

907+
@patch_list(sys.meta_path)
907908
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+
908918
cases = (
909919
("import path\t\n", "import pathlib"),
910920
("import importlib.\t\tres\t\n", "import importlib.resources"),

0 commit comments

Comments
 (0)