mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #8766: Initialize _warnings module before importing the first module.
Fix a crash if an empty directory called "encodings" exists in sys.path.
This commit is contained in:
parent
5b08b4d230
commit
7d79b8b771
4 changed files with 36 additions and 13 deletions
|
@ -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__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue