@@ -917,7 +917,14 @@ def test_func(self):
917
917
918
918
class TestPyReplModuleCompleter (TestCase ):
919
919
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 ])
920
926
self ._saved_sys_path = sys .path
927
+ sys .path = [lib_path ]
921
928
922
929
def tearDown (self ):
923
930
sys .path = self ._saved_sys_path
@@ -929,17 +936,7 @@ def prepare_reader(self, events, namespace):
929
936
reader = ReadlineAlikeReader (console = console , config = config )
930
937
return reader
931
938
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
-
941
939
def test_import_completions (self ):
942
- self ._only_stdlib_imports ()
943
940
cases = (
944
941
("import path\t \n " , "import pathlib" ),
945
942
("import importlib.\t \t res\t \n " , "import importlib.resources" ),
@@ -991,7 +988,6 @@ def test_invalid_identifiers(self):
991
988
self .assertEqual (output , expected )
992
989
993
990
def test_no_fallback_on_regular_completion (self ):
994
- self ._only_stdlib_imports ()
995
991
cases = (
996
992
("import pri\t \n " , "import pri" ),
997
993
("from pri\t \n " , "from pri" ),
0 commit comments