              call_command, but SystemExit when run from command line
          """
          with self.assertRaises(CommandError):
              management.call_command('dance', example="raise")
          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())
  
      def test_default_en_us_locale_set(self):
          # Forces en_us when set to true
          out = StringIO()
          with translation.override('pl'):
 
</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         finally:
            output = sys.stdout.getvalue()
            sys.stdout, sys.stderr = old_stdout, old_stderr
        self.assertEqual(output, "All right, let's dance Rock'n'Roll.\n")
 </s> add         self.assertEqual(stdout.getvalue(), "All right, let's dance Rock'n'Roll.\n") </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         _stderr = sys.stderr
        sys.stderr = StringIO()
        try:
 </s> add         with captured_stderr() as stderr:
        with captured_stderr() as stderr, self.assertRaises(SystemExit):
            management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        self.assertIn("CommandError", stderr.getvalue())
              call_command, but SystemExit when run from command line
          """
          with self.assertRaises(CommandError):
              management.call_command('dance', example="raise")
        with captured_stderr() as stderr, self.assertRaises(SystemExit):
            management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        self.assertIn("CommandError", stderr.getvalue())
        with captured_stderr() as stderr, self.assertRaises(SystemExit):
            management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        self.assertIn("CommandError", stderr.getvalue())
        with captured_stderr() as stderr, self.assertRaises(SystemExit):
            management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        self.assertIn("CommandError", stderr.getvalue())
        with captured_stderr() as stderr, self.assertRaises(SystemExit):
            management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        self.assertIn("CommandError", stderr.getvalue())
        with captured_stderr() as stderr, self.assertRaises(SystemExit):
            management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        self.assertIn("CommandError", stderr.getvalue())
        with captured_stderr() as stderr, self.assertRaises(SystemExit):
            management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        self.assertIn("CommandError", stderr.getvalue())
        with captured_stderr() as stderr, self.assertRaises(SystemExit):
            management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        self.assertIn("CommandError", stderr.getvalue())
        with captured_stderr() as stderr, self.assertRaises(SystemExit):
            management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        self.assertIn("CommandError", stderr.getvalue())
  
      def test_default_en_us_locale_set(self):
          # Forces en_us when set to true
          out = StringIO()
          with translation.override('pl'):
keep keep keep keep replace replace replace replace replace replace 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/user_commands/tests.py