@@ -807,19 +807,24 @@ def test_underpth_dll_file(self):
807807
808808
809809class CommandLineTests (unittest .TestCase ):
810- def setUp (self ):
811- super ().setUp ()
812- self .maxDiff = None # TODO: For test only, should be removed
813- if sys .path [0 ] != os .getcwd ():
814- sys .path .remove (sys .path [0 ])
815- sys .path .insert (0 , os .getcwd ())
810+ def get_sys_path (self ):
811+ proc = subprocess .Popen ([sys .executable , '-c' ,
812+ 'import sys; print(repr(sys.path))' ],
813+ stdout = subprocess .PIPE ,
814+ stderr = subprocess .STDOUT ,
815+ text = True )
816+ proc .wait ()
817+ ls = ast .literal_eval (proc .stdout .read ())
818+ if ls [0 ] == '' :
819+ ls [0 ] = os .getcwd ()
820+ return ls
816821
817822 def get_excepted_output (self , * args ):
818823 if len (args ) == 0 :
819824 user_base = site .getuserbase ()
820825 user_site = site .getusersitepackages ()
821826 output = "sys.path = [\n "
822- for dir in sys . path :
827+ for dir in self . get_sys_path () :
823828 output += " %r,\n " % (dir ,)
824829 output += "]\n "
825830 def exists (path ):
@@ -855,9 +860,10 @@ def invoke_command_line(self, *args):
855860 args = [sys .executable , "-m" , "site" , * args ]
856861 proc = subprocess .Popen (args ,
857862 stdout = subprocess .PIPE ,
858- stderr = subprocess .STDOUT ,)
863+ stderr = subprocess .STDOUT ,
864+ text = True )
859865 proc .wait ()
860- output = proc .stdout .read (). decode ()
866+ output = proc .stdout .read ()
861867 return_code = proc .returncode
862868 proc .stdout .close ()
863869 return return_code , dedent (output ).strip ()
0 commit comments