diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-19 20:40:50 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-19 20:40:50 (GMT) |
commit | 7d79b8b7714b5e7d8a0582a07b5625c280c879c0 (patch) | |
tree | beb8d4f6b49623a468815c33febd040fa5301b11 /Lib/test/test_warnings.py | |
parent | 5b08b4d230d95fe6a0b24dc45463e785a27fecd2 (diff) | |
download | cpython-7d79b8b7714b5e7d8a0582a07b5625c280c879c0.zip cpython-7d79b8b7714b5e7d8a0582a07b5625c280c879c0.tar.gz cpython-7d79b8b7714b5e7d8a0582a07b5625c280c879c0.tar.bz2 |
Issue #8766: Initialize _warnings module before importing the first module.
Fix a crash if an empty directory called "encodings" exists in sys.path.
Diffstat (limited to 'Lib/test/test_warnings.py')
-rw-r--r-- | Lib/test/test_warnings.py | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index 5f6a670..52b9dbe 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -738,20 +738,38 @@ class PyEnvironmentVariableTests(EnvironmentVariableTests): module = py_warnings +class BootstrapTest(unittest.TestCase): + def test_issue_8766(self): + # "import encodings" emits a warning whereas the warnings is not loaded + # or not completly loaded (warnings imports indirectly encodings by + # importing linecache) yet + with support.temp_cwd() as cwd, support.temp_cwd('encodings'): + env = os.environ.copy() + env['PYTHONPATH'] = cwd + + # encodings loaded by initfsencoding() + retcode = subprocess.call([sys.executable, '-c', 'pass'], env=env) + self.assertEqual(retcode, 0) + + # Use -W to load warnings module at startup + retcode = subprocess.call( + [sys.executable, '-c', 'pass', '-W', 'always'], + env=env) + self.assertEqual(retcode, 0) + def test_main(): py_warnings.onceregistry.clear() c_warnings.onceregistry.clear() - support.run_unittest(CFilterTests, - PyFilterTests, - CWarnTests, - PyWarnTests, - CWCmdLineTests, PyWCmdLineTests, - _WarningsTests, - CWarningsDisplayTests, PyWarningsDisplayTests, - CCatchWarningTests, PyCatchWarningTests, - CEnvironmentVariableTests, - PyEnvironmentVariableTests - ) + support.run_unittest( + CFilterTests, PyFilterTests, + CWarnTests, PyWarnTests, + CWCmdLineTests, PyWCmdLineTests, + _WarningsTests, + CWarningsDisplayTests, PyWarningsDisplayTests, + CCatchWarningTests, PyCatchWarningTests, + CEnvironmentVariableTests, PyEnvironmentVariableTests, + BootstrapTest, + ) if __name__ == "__main__": |