Index: Lib/unittest/test/test_program.py =================================================================== --- Lib/unittest/test/test_program.py (revision 86636) +++ Lib/unittest/test/test_program.py (working copy) @@ -64,16 +64,23 @@ return self.suiteClass( [self.loadTestsFromTestCase(Test_TestProgram.FooBar)]) + def register_restore_path(self): + """Used by tests that invoke discovery, which may modify sys.path""" + orig_sys_path = sys.path[:] + def restore_path(): + sys.path[:] = orig_sys_path + self.addCleanup(restore_path) def test_NonExit(self): + self.register_restore_path() program = unittest.main(exit=False, argv=["foobar"], testRunner=unittest.TextTestRunner(stream=io.StringIO()), testLoader=self.FooBarLoader()) self.assertTrue(hasattr(program, 'result')) - def test_Exit(self): + self.register_restore_path() self.assertRaises( SystemExit, unittest.main, @@ -84,6 +91,7 @@ def test_ExitAsDefault(self): + self.register_restore_path() self.assertRaises( SystemExit, unittest.main,