Check and revert expected sys.path alterations
This commit is contained in:
parent
a3e97ad5ba
commit
b6edf193fb
|
@ -3609,12 +3609,12 @@ class TestDiscovery(TestCase):
|
||||||
os.path.isfile = lambda path: False
|
os.path.isfile = lambda path: False
|
||||||
self.addCleanup(restore_isfile)
|
self.addCleanup(restore_isfile)
|
||||||
|
|
||||||
full_path = os.path.abspath(os.path.normpath('/foo'))
|
orig_sys_path = sys.path[:]
|
||||||
def clean_path():
|
def restore_path():
|
||||||
if sys.path[-1] == full_path:
|
sys.path[:] = orig_sys_path
|
||||||
sys.path.pop(-1)
|
self.addCleanup(restore_path)
|
||||||
self.addCleanup(clean_path)
|
|
||||||
|
|
||||||
|
full_path = os.path.abspath(os.path.normpath('/foo'))
|
||||||
with self.assertRaises(ImportError):
|
with self.assertRaises(ImportError):
|
||||||
loader.discover('/foo/bar', top_level_dir='/foo')
|
loader.discover('/foo/bar', top_level_dir='/foo')
|
||||||
|
|
||||||
|
@ -3636,6 +3636,7 @@ class TestDiscovery(TestCase):
|
||||||
self.assertEqual(suite, "['tests']")
|
self.assertEqual(suite, "['tests']")
|
||||||
self.assertEqual(loader._top_level_dir, top_level_dir)
|
self.assertEqual(loader._top_level_dir, top_level_dir)
|
||||||
self.assertEqual(_find_tests_args, [(start_dir, 'pattern')])
|
self.assertEqual(_find_tests_args, [(start_dir, 'pattern')])
|
||||||
|
self.assertIn(top_level_dir, sys.path)
|
||||||
|
|
||||||
def test_discover_with_modules_that_fail_to_import(self):
|
def test_discover_with_modules_that_fail_to_import(self):
|
||||||
loader = unittest.TestLoader()
|
loader = unittest.TestLoader()
|
||||||
|
@ -3644,12 +3645,15 @@ class TestDiscovery(TestCase):
|
||||||
os.listdir = lambda _: ['test_this_does_not_exist.py']
|
os.listdir = lambda _: ['test_this_does_not_exist.py']
|
||||||
isfile = os.path.isfile
|
isfile = os.path.isfile
|
||||||
os.path.isfile = lambda _: True
|
os.path.isfile = lambda _: True
|
||||||
|
orig_sys_path = sys.path[:]
|
||||||
def restore():
|
def restore():
|
||||||
os.path.isfile = isfile
|
os.path.isfile = isfile
|
||||||
os.listdir = listdir
|
os.listdir = listdir
|
||||||
|
sys.path[:] = orig_sys_path
|
||||||
self.addCleanup(restore)
|
self.addCleanup(restore)
|
||||||
|
|
||||||
suite = loader.discover('.')
|
suite = loader.discover('.')
|
||||||
|
self.assertIn(os.getcwd(), sys.path)
|
||||||
self.assertEqual(suite.countTestCases(), 1)
|
self.assertEqual(suite.countTestCases(), 1)
|
||||||
test = list(list(suite)[0])[0] # extract test from suite
|
test = list(list(suite)[0])[0] # extract test from suite
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue