Skip to content

Commit 98917e5

Browse files
committed
Silence error output
1 parent 05a205f commit 98917e5

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Lib/test/test_tools/test_msgfmt.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import struct
55
import sys
66
import unittest
7+
from contextlib import redirect_stderr
78
from gettext import GNUTranslations
9+
from io import StringIO
810
from pathlib import Path
11+
from textwrap import dedent
912

1013
from test.support.os_helper import temp_cwd
1114
from test.support.script_helper import assert_python_failure, assert_python_ok
1215
from test.test_tools import imports_under_tool, skip_if_missing, toolsdir
13-
from textwrap import dedent
1416

1517

1618
skip_if_missing('i18n')
@@ -320,9 +322,10 @@ def test_general_syntax_errors(self):
320322
Path('messages.po').write_text(invalid_po)
321323
# Reset the global MESSAGES dictionary
322324
msgfmt.MESSAGES.clear()
323-
with self.assertRaises((SystemExit, UnboundLocalError,
324-
IndexError, SyntaxError)):
325-
msgfmt.make('messages.po', 'messages.mo')
325+
with redirect_stderr(StringIO()) as output:
326+
with self.assertRaises((SystemExit, UnboundLocalError,
327+
IndexError, SyntaxError)):
328+
msgfmt.make('messages.po', 'messages.mo')
326329

327330
def test_semantic_errors(self):
328331
invalid_po_files = (
@@ -394,8 +397,9 @@ def test_semantic_errors(self):
394397
Path('messages.po').write_text(invalid_po)
395398
# Reset the global MESSAGES dictionary
396399
msgfmt.MESSAGES.clear()
397-
with self.assertRaises((SystemExit, UnboundLocalError)):
398-
msgfmt.make('messages.po', 'messages.mo')
400+
with redirect_stderr(StringIO()) as output:
401+
with self.assertRaises((SystemExit, UnboundLocalError)):
402+
msgfmt.make('messages.po', 'messages.mo')
399403

400404
def test_msgstr_invalid_indices(self):
401405
invalid_po_files = (
@@ -412,8 +416,9 @@ def test_msgstr_invalid_indices(self):
412416
Path('messages.po').write_text(invalid_po)
413417
# Reset the global MESSAGES dictionary
414418
msgfmt.MESSAGES.clear()
415-
with self.assertRaises(SystemExit):
416-
msgfmt.make('messages.po', 'messages.mo')
419+
with redirect_stderr(StringIO()) as output:
420+
with self.assertRaises(SystemExit):
421+
msgfmt.make('messages.po', 'messages.mo')
417422

418423

419424
class CLITest(unittest.TestCase):

0 commit comments

Comments
 (0)