Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ce881e

Browse files
author
Victor Stinner
committed
Fix my test introduced in test_sys by r79394:
Restore the orginal filesystem encoding before testing assertRaises(LookupError, sys.setfilesystemencoding, "xxx"). Unittest formats the exception, but the formatting failed because the file system was invalid (set to iso-8859-1 by the previous test). Anyway, ensure to restore the original filesystem encoding when exiting test_setfilesystemencoding() to avoid error propagation to the other tests.
1 parent e777a68 commit 4ce881e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

Lib/test/test_sys.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,15 @@ def test_pythontypes(self):
797797

798798
def test_setfilesystemencoding(self):
799799
old = sys.getfilesystemencoding()
800-
sys.setfilesystemencoding("iso-8859-1")
801-
self.assertEqual(sys.getfilesystemencoding(), "iso-8859-1")
802-
self.assertRaises(LookupError, sys.setfilesystemencoding, "xxx")
803-
sys.setfilesystemencoding(old)
800+
try:
801+
sys.setfilesystemencoding("iso-8859-1")
802+
self.assertEqual(sys.getfilesystemencoding(), "iso-8859-1")
803+
finally:
804+
sys.setfilesystemencoding(old)
805+
try:
806+
self.assertRaises(LookupError, sys.setfilesystemencoding, "xxx")
807+
finally:
808+
sys.setfilesystemencoding(old)
804809

805810
def test_main():
806811
test.support.run_unittest(SysModuleTest, SizeofTest)

0 commit comments

Comments
 (0)