for n, line in enumerate(f):
if line.startswith("#"):
continue
+ if line.strip() == "":
+ continue
try:
if line.startswith(("import ", "import\t")):
exec(line)
self.assertRegex(err_out.getvalue(), 'Traceback')
self.assertRegex(err_out.getvalue(), 'ModuleNotFoundError')
+ def test_addpackage_empty_lines(self):
+ # Issue 33689
+ pth_dir, pth_fn = self.make_pth("\n\n \n\n")
+ known_paths = site.addpackage(pth_dir, pth_fn, set())
+ self.assertEqual(known_paths, set())
+
def test_addpackage_import_bad_pth_file(self):
# Issue 5258
pth_dir, pth_fn = self.make_pth("abc\x00def\n")
'import site, sys; site.enablerlcompleter(); sys.exit(hasattr(sys, "__interactivehook__"))']).wait()
self.assertTrue(r, "'__interactivehook__' not added by enablerlcompleter()")
-
@unittest.skipUnless(sys.platform == 'win32', "only supported on Windows")
class _pthFileTests(unittest.TestCase):
--- /dev/null
+Ignore empty or whitespace-only lines in .pth files. This matches the\r
+documentated behavior. Before, empty lines caused the site-packages\r
+dir to appear multiple times in sys.path.\r
+By Ido Michael, contributors Malcolm Smith and Tal Einat.\r