]> granicus.if.org Git - python/commitdiff
Isolate the test_source() test in test_collections
authorRaymond Hettinger <python@rcn.com>
Thu, 24 Mar 2011 16:45:43 +0000 (09:45 -0700)
committerRaymond Hettinger <python@rcn.com>
Thu, 24 Mar 2011 16:45:43 +0000 (09:45 -0700)
Lib/test/test_collections.py

index 4ef27ce2c50773d979167f7f9623e9d340a9f9a2..020f4e2a8161dcbaa99fc283a87c428d4a536ad0 100644 (file)
@@ -330,13 +330,16 @@ class TestNamedTuple(unittest.TestCase):
 
     def test_source(self):
         # verify that _source can be run through exec()
-        tmp = namedtuple('Color', 'red green blue')
-        self.assertNotIn('Color', globals())
+        tmp = namedtuple('NTColor', 'red green blue')
+        globals().pop('NTColor', None)          # remove artifacts from other tests
+        self.assertNotIn('NTColor', globals())
         exec(tmp._source, globals())
-        self.assertIn('Color', globals())
-        c = Color(10, 20, 30)
+        self.assertIn('NTColor', globals())
+        c = NTColor(10, 20, 30)
         self.assertEqual((c.red, c.green, c.blue), (10, 20, 30))
-        self.assertEqual(Color._fields, ('red', 'green', 'blue'))
+        self.assertEqual(NTColor._fields, ('red', 'green', 'blue'))
+        globals().pop('NTColor', None)          # clean-up after this test
+        self.assertNotIn('NTColor', globals())
 
     def test_source_importable(self):
         tmp = namedtuple('Color', 'hue sat val')