              # `call_command` bypasses the parser; by calling
              # `execute_from_command_line` with the help subcommand we
              # ensure that there are no issues with the parser itself.
              execute_from_command_line(['django-admin', 'help', 'makemessages'])
          finally:
              sys.stdout, sys.stderr = old_stdout, old_stderr
  
      def test_one_locale_excluded(self):
          management.call_command('makemessages', exclude=['it'], stdout=StringIO())
          self.assertRecentlyModified(self.PO_FILE % 'en')
          self.assertRecentlyModified(self.PO_FILE % 'fr')
 
</s> remove         finally:
            sys.stdout, sys.stderr = old_stdout, old_stderr
 </s> add  </s> remove         old_stdout, old_stderr = sys.stdout, sys.stderr
        sys.stdout, sys.stderr = StringIO(), StringIO()
        try:
 </s> add         with captured_stdout(), captured_stderr(): </s> remove         old_stdout, old_stderr = sys.stdout, sys.stderr
        sys.stdout, sys.stderr = StringIO(), StringIO()
        try:
 </s> add         with captured_stdout(), captured_stderr(): </s> remove         old_stdout, old_stderr = sys.stdout, sys.stderr
        sys.stdout, sys.stderr = StringIO(), StringIO()
        try:
 </s> add         with captured_stdout() as stdout, captured_stderr(): </s> remove         old_stderr = sys.stderr
        sys.stderr = err = StringIO()
        try:
            with self.assertRaises(SystemExit):
                management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        finally:
            sys.stderr = old_stderr
        self.assertIn("CommandError", err.getvalue())
 </s> add         with captured_stderr() as stderr, self.assertRaises(SystemExit):
            management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        self.assertIn("CommandError", stderr.getvalue())
              # `call_command` bypasses the parser; by calling
              # `execute_from_command_line` with the help subcommand we
              # ensure that there are no issues with the parser itself.
              execute_from_command_line(['django-admin', 'help', 'makemessages'])


  
      def test_one_locale_excluded(self):
          management.call_command('makemessages', exclude=['it'], stdout=StringIO())
          self.assertRecentlyModified(self.PO_FILE % 'en')
          self.assertRecentlyModified(self.PO_FILE % 'fr')
keep keep keep keep replace replace keep keep keep keep keep
 Fixed #23930 -- Added copies of captured_std* managers from CPython's test.support.

StringIO import was adapted for compatibility with Python 2. 
tests/i18n/test_extraction.py