summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_warnings
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-24 23:33:12 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-24 23:33:12 (GMT)
commite091d32a7ac514a415161043c4a70e1765363c5a (patch)
treef1c6f637623209de8eab8ce03f8e9596f8909415 /Lib/test/test_warnings
parent3aac0adfe01b30fc58c638c5ab61844e80b3fd66 (diff)
parent27461683a9491efe58331a695c856fbb28bd4cba (diff)
downloadcpython-e091d32a7ac514a415161043c4a70e1765363c5a.zip
cpython-e091d32a7ac514a415161043c4a70e1765363c5a.tar.gz
cpython-e091d32a7ac514a415161043c4a70e1765363c5a.tar.bz2
Merge 3.5
Issue #21925: warnings.formatwarning() now catches exceptions when calling linecache.getline() and tracemalloc.get_object_traceback() to be able to log ResourceWarning emitted late during the Python shutdown process.
Diffstat (limited to 'Lib/test/test_warnings')
-rw-r--r--Lib/test/test_warnings/__init__.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
index e6f47cd..9f1cd75 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -536,6 +536,14 @@ class WCmdLineTests(BaseTest):
self.module._setoption('error::Warning::0')
self.assertRaises(UserWarning, self.module.warn, 'convert to error')
+
+class CWCmdLineTests(WCmdLineTests, unittest.TestCase):
+ module = c_warnings
+
+
+class PyWCmdLineTests(WCmdLineTests, unittest.TestCase):
+ module = py_warnings
+
def test_improper_option(self):
# Same as above, but check that the message is printed out when
# the interpreter is executed. This also checks that options are
@@ -552,12 +560,6 @@ class WCmdLineTests(BaseTest):
self.assertFalse(out.strip())
self.assertNotIn(b'RuntimeWarning', err)
-class CWCmdLineTests(WCmdLineTests, unittest.TestCase):
- module = c_warnings
-
-class PyWCmdLineTests(WCmdLineTests, unittest.TestCase):
- module = py_warnings
-
class _WarningsTests(BaseTest, unittest.TestCase):
@@ -976,6 +978,7 @@ class BootstrapTest(unittest.TestCase):
# Use -W to load warnings module at startup
assert_python_ok('-c', 'pass', '-W', 'always', PYTHONPATH=cwd)
+
class FinalizationTest(unittest.TestCase):
def test_finalization(self):
# Issue #19421: warnings.warn() should not crash
@@ -995,6 +998,23 @@ a=A()
# of the script
self.assertEqual(err, b'__main__:7: UserWarning: test')
+ def test_late_resource_warning(self):
+ # Issue #21925: Emitting a ResourceWarning late during the Python
+ # shutdown must be logged.
+
+ expected = b"sys:1: ResourceWarning: unclosed file "
+
+ # don't import the warnings module
+ # (_warnings will try to import it)
+ code = "f = open(%a)" % __file__
+ rc, out, err = assert_python_ok("-c", code)
+ self.assertTrue(err.startswith(expected), ascii(err))
+
+ # import the warnings module
+ code = "import warnings; f = open(%a)" % __file__
+ rc, out, err = assert_python_ok("-c", code)
+ self.assertTrue(err.startswith(expected), ascii(err))
+
def setUpModule():
py_warnings.onceregistry.clear()