@@ -738,20 +738,38 @@ class PyEnvironmentVariableTests(EnvironmentVariableTests):
738738 module = py_warnings
739739
740740
741+ class BootstrapTest (unittest .TestCase ):
742+ def test_issue_8766 (self ):
743+ # "import encodings" emits a warning whereas the warnings is not loaded
744+ # or not completly loaded (warnings imports indirectly encodings by
745+ # importing linecache) yet
746+ with support .temp_cwd () as cwd , support .temp_cwd ('encodings' ):
747+ env = os .environ .copy ()
748+ env ['PYTHONPATH' ] = cwd
749+
750+ # encodings loaded by initfsencoding()
751+ retcode = subprocess .call ([sys .executable , '-c' , 'pass' ], env = env )
752+ self .assertEqual (retcode , 0 )
753+
754+ # Use -W to load warnings module at startup
755+ retcode = subprocess .call (
756+ [sys .executable , '-c' , 'pass' , '-W' , 'always' ],
757+ env = env )
758+ self .assertEqual (retcode , 0 )
759+
741760def test_main ():
742761 py_warnings .onceregistry .clear ()
743762 c_warnings .onceregistry .clear ()
744- support .run_unittest (CFilterTests ,
745- PyFilterTests ,
746- CWarnTests ,
747- PyWarnTests ,
748- CWCmdLineTests , PyWCmdLineTests ,
749- _WarningsTests ,
750- CWarningsDisplayTests , PyWarningsDisplayTests ,
751- CCatchWarningTests , PyCatchWarningTests ,
752- CEnvironmentVariableTests ,
753- PyEnvironmentVariableTests
754- )
763+ support .run_unittest (
764+ CFilterTests , PyFilterTests ,
765+ CWarnTests , PyWarnTests ,
766+ CWCmdLineTests , PyWCmdLineTests ,
767+ _WarningsTests ,
768+ CWarningsDisplayTests , PyWarningsDisplayTests ,
769+ CCatchWarningTests , PyCatchWarningTests ,
770+ CEnvironmentVariableTests , PyEnvironmentVariableTests ,
771+ BootstrapTest ,
772+ )
755773
756774
757775if __name__ == "__main__" :
0 commit comments