@@ -913,8 +913,9 @@ def setUp(self):
913913 self .enterContext (import_helper .DirsOnSysPath ())
914914 self .tmpdir = self .sitedir = self .enterContext (os_helper .temp_dir ())
915915 # Each test gets its own StartupState to batch the parsing and
916- # explicitly invoke the processing.
917- self .state = site .StartupState ()
916+ # explicitly invoke the processing. Seed with an empty known_paths
917+ # so dedup is not influenced by the current sys.path.
918+ self .state = site .StartupState (known_paths = set ())
918919
919920 def _make_start (self , content , name = 'testpkg' , basedir = None ):
920921 """Write a <name>.start file and return its basename.
@@ -1131,33 +1132,33 @@ def test_impl_read_pth_file_paths(self):
11311132 subdir = os .path .join (self .sitedir , 'mylib' )
11321133 os .mkdir (subdir )
11331134 self ._make_pth ("mylib\n " , name = 'foo' )
1134- self .state ._read_pth_file (self .sitedir , 'foo.pth' , set () )
1135+ self .state ._read_pth_file (self .sitedir , 'foo.pth' )
11351136 fullname = os .path .join (self .sitedir , 'foo.pth' )
11361137 self .assertIn ((fullname , subdir ), self .state ._path_entries )
11371138
11381139 def test_impl_read_pth_file_imports_collected (self ):
11391140 self ._make_pth ("import sys\n " , name = 'foo' )
1140- self .state ._read_pth_file (self .sitedir , 'foo.pth' , set () )
1141+ self .state ._read_pth_file (self .sitedir , 'foo.pth' )
11411142 fullname = os .path .join (self .sitedir , 'foo.pth' )
11421143 self .assertEqual (
11431144 self .state ._importexecs [fullname ], ['import sys' ]
11441145 )
11451146
11461147 def test_impl_read_pth_file_comments_and_blanks (self ):
11471148 self ._make_pth ("# comment\n \n \n " , name = 'foo' )
1148- self .state ._read_pth_file (self .sitedir , 'foo.pth' , set () )
1149+ self .state ._read_pth_file (self .sitedir , 'foo.pth' )
11491150 self .assertEqual (self .state ._path_entries , [])
11501151 self .assertEqual (self .state ._importexecs , {})
11511152
11521153 def test_impl_read_pth_file_deduplication (self ):
11531154 subdir = os .path .join (self .sitedir , 'mylib' )
11541155 os .mkdir (subdir )
1155- # An accumulator acts as a deduplication ledger.
1156- known_paths = set ()
1156+ # self.state._known_paths acts as the deduplication ledger across
1157+ # both reads.
11571158 self ._make_pth ("mylib\n " , name = 'a' )
11581159 self ._make_pth ("mylib\n " , name = 'b' )
1159- self .state ._read_pth_file (self .sitedir , 'a.pth' , known_paths )
1160- self .state ._read_pth_file (self .sitedir , 'b.pth' , known_paths )
1160+ self .state ._read_pth_file (self .sitedir , 'a.pth' )
1161+ self .state ._read_pth_file (self .sitedir , 'b.pth' )
11611162 # There is only one entry across both files.
11621163 all_dirs = [dir_ for filename , dir_ in self .state ._path_entries ]
11631164 self .assertEqual (all_dirs , [subdir ])
@@ -1168,7 +1169,7 @@ def test_impl_read_pth_file_bad_line_continues(self):
11681169 os .mkdir (subdir )
11691170 self ._make_pth ("abc\x00 def\n goodpath\n " , name = 'foo' )
11701171 with captured_stderr ():
1171- self .state ._read_pth_file (self .sitedir , 'foo.pth' , set () )
1172+ self .state ._read_pth_file (self .sitedir , 'foo.pth' )
11721173 fullname = os .path .join (self .sitedir , 'foo.pth' )
11731174 self .assertIn ((fullname , subdir ), self .state ._path_entries )
11741175
@@ -1192,7 +1193,7 @@ def test_impl_read_pth_file_parse_error_silent_by_default(self):
11921193 mock .patch ('sys.flags' , self ._flags_with_verbose (False )),
11931194 captured_stderr () as err ,
11941195 ):
1195- self .state ._read_pth_file (self .sitedir , 'foo.pth' , set () )
1196+ self .state ._read_pth_file (self .sitedir , 'foo.pth' )
11961197 self .assertEqual (err .getvalue (), "" )
11971198
11981199 def test_impl_read_pth_file_parse_error_reported_under_verbose (self ):
@@ -1203,7 +1204,7 @@ def test_impl_read_pth_file_parse_error_reported_under_verbose(self):
12031204 mock .patch ('sys.flags' , self ._flags_with_verbose (True )),
12041205 captured_stderr () as err ,
12051206 ):
1206- self .state ._read_pth_file (self .sitedir , 'foo.pth' , set () )
1207+ self .state ._read_pth_file (self .sitedir , 'foo.pth' )
12071208 out = err .getvalue ()
12081209 self .assertIn ('Error in' , out )
12091210 self .assertIn ('foo.pth' , out )
@@ -1223,7 +1224,7 @@ def test_impl_read_pth_file_locale_fallback(self):
12231224 mock .patch ('locale.getencoding' , return_value = 'latin-1' ),
12241225 captured_stderr (),
12251226 ):
1226- self .state ._read_pth_file (self .sitedir , 'foo.pth' , set () )
1227+ self .state ._read_pth_file (self .sitedir , 'foo.pth' )
12271228 fullname = os .path .join (self .sitedir , 'foo.pth' )
12281229 self .assertIn ((fullname , subdir ), self .state ._path_entries )
12291230
@@ -1353,7 +1354,7 @@ def startup():
13531354 global called
13541355 called = True
13551356""" , name = 'epmod' , package = True , on_path = True )
1356- self .state ._read_pth_file (self .sitedir , 'foo.pth' , set () )
1357+ self .state ._read_pth_file (self .sitedir , 'foo.pth' )
13571358 self .state ._read_start_file (self .sitedir , 'foo.start' )
13581359 self .state ._exec_imports ()
13591360 import epmod
0 commit comments