Merged revisions 70965 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r70965 | brett.cannon | 2009-04-01 11:03:59 -0700 (Wed, 01 Apr 2009) | 5 lines

  _warnings was importing itself to get an attribute. That's bad if warnings gets
  called in a thread that was spawned by an import itself.

  Last part to close #1665206.
........
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index 4b6feb3..49f3d3a 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -423,6 +423,41 @@
         finally:
             self.module.onceregistry = original_registry
 
+    def test_default_action(self):
+        # Replacing or removing defaultaction should be okay.
+        message = UserWarning("defaultaction test")
+        original = self.module.defaultaction
+        try:
+            with original_warnings.catch_warnings(record=True,
+                    module=self.module) as w:
+                self.module.resetwarnings()
+                registry = {}
+                self.module.warn_explicit(message, UserWarning, "<test>", 42,
+                                            registry=registry)
+                self.assertEqual(w[-1].message, message)
+                self.assertEqual(len(w), 1)
+                self.assertEqual(len(registry), 1)
+                del w[:]
+                # Test removal.
+                del self.module.defaultaction
+                __warningregistry__ = {}
+                registry = {}
+                self.module.warn_explicit(message, UserWarning, "<test>", 43,
+                                            registry=registry)
+                self.assertEqual(w[-1].message, message)
+                self.assertEqual(len(w), 1)
+                self.assertEqual(len(registry), 1)
+                del w[:]
+                # Test setting.
+                self.module.defaultaction = "ignore"
+                __warningregistry__ = {}
+                registry = {}
+                self.module.warn_explicit(message, UserWarning, "<test>", 44,
+                                            registry=registry)
+                self.assertEqual(len(w), 0)
+        finally:
+            self.module.defaultaction = original
+
     def test_showwarning_missing(self):
         # Test that showwarning() missing is okay.
         text = 'del showwarning test'