          self.old_stdout = sys.stdout
          sys.stdout = self.output
  
      def tearDown(self):
          sys.stdout = self.old_stdout
          if self.old_DJANGO_AUTO_COMPLETE:
              os.environ['DJANGO_AUTO_COMPLETE'] = self.old_DJANGO_AUTO_COMPLETE
          else:
              del os.environ['DJANGO_AUTO_COMPLETE']
  
 
</s> remove         self.output = StringIO()
        self.old_stdout = sys.stdout
        sys.stdout = self.output
 </s> add  </s> remove         self.old_stdout = sys.stdout
        sys.stdout = StringIO()

    def tearDown(self):
        sys.stdout = self.old_stdout
 </s> add  </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_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()) </s> remove         _stderr = sys.stderr
        sys.stderr = StringIO()
        try:
 </s> add         with captured_stderr() as stderr:
          self.old_stdout = sys.stdout
          sys.stdout = self.output
  
      def tearDown(self):

          if self.old_DJANGO_AUTO_COMPLETE:
              os.environ['DJANGO_AUTO_COMPLETE'] = self.old_DJANGO_AUTO_COMPLETE
          else:
              del os.environ['DJANGO_AUTO_COMPLETE']
  
keep keep keep keep 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/bash_completion/tests.py