From 5d62a61b58bc2d42a734be24f58e64ef18c04e76 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 8 Jul 2012 13:48:46 +0200 Subject: Fix test_inspect messing up with linecache.cache. --- Lib/test/test_inspect.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 7ed4ffe..80db03b 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -285,7 +285,10 @@ class TestRetrievingSourceCode(GetSourceBase): co = compile("None", fn, "exec") self.assertEqual(inspect.getsourcefile(co), None) linecache.cache[co.co_filename] = (1, None, "None", co.co_filename) - self.assertEqual(normcase(inspect.getsourcefile(co)), fn) + try: + self.assertEqual(normcase(inspect.getsourcefile(co)), fn) + finally: + del linecache.cache[co.co_filename] def test_getfile(self): self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__) @@ -407,8 +410,11 @@ class TestBuggyCases(GetSourceBase): self.assertRaises(IOError, inspect.findsource, co) self.assertRaises(IOError, inspect.getsource, co) linecache.cache[co.co_filename] = (1, None, lines, co.co_filename) - self.assertEqual(inspect.findsource(co), (lines,0)) - self.assertEqual(inspect.getsource(co), lines[0]) + try: + self.assertEqual(inspect.findsource(co), (lines,0)) + self.assertEqual(inspect.getsource(co), lines[0]) + finally: + del linecache.cache[co.co_filename] class TestNoEOL(GetSourceBase): def __init__(self, *args, **kwargs): -- cgit v0.12