@@ -917,7 +917,14 @@ def test_func(self):
917917
918918class TestPyReplModuleCompleter (TestCase ):
919919 def setUp (self ):
920+ import importlib
921+ # Make iter_modules() search only the standard library.
922+ # This makes the test more reliable in case there are
923+ # other user packages/scripts on PYTHONPATH which can
924+ # interfere with the completions.
925+ lib_path = os .path .dirname (importlib .__path__ [0 ])
920926 self ._saved_sys_path = sys .path
927+ sys .path = [lib_path ]
921928
922929 def tearDown (self ):
923930 sys .path = self ._saved_sys_path
@@ -929,17 +936,7 @@ def prepare_reader(self, events, namespace):
929936 reader = ReadlineAlikeReader (console = console , config = config )
930937 return reader
931938
932- def _only_stdlib_imports (self ):
933- import importlib
934- # Make iter_modules() search only the standard library.
935- # This makes the test more reliable in case there are
936- # other user packages/scripts on PYTHONPATH which can
937- # intefere with the completions.
938- lib_path = os .path .dirname (importlib .__path__ [0 ])
939- sys .path = [lib_path ]
940-
941939 def test_import_completions (self ):
942- self ._only_stdlib_imports ()
943940 cases = (
944941 ("import path\t \n " , "import pathlib" ),
945942 ("import importlib.\t \t res\t \n " , "import importlib.resources" ),
@@ -991,7 +988,6 @@ def test_invalid_identifiers(self):
991988 self .assertEqual (output , expected )
992989
993990 def test_no_fallback_on_regular_completion (self ):
994- self ._only_stdlib_imports ()
995991 cases = (
996992 ("import pri\t \n " , "import pri" ),
997993 ("from pri\t \n " , "from pri" ),
0 commit comments