          """
          non-interactive mode of update_contenttypes() shouldn't delete stale
          content types.
          """
          management.update_contenttypes(self.app_config, interactive=False)
          self.assertIn("Stale content types remain.", sys.stdout.getvalue())
          self.assertEqual(ContentType.objects.count(), self.before_count + 1)
  
  
  class TestRouter(object):
      def db_for_read(self, model, **hints):
 
</s> remove         management.update_contenttypes(self.app_config)
        self.assertIn("Deleting stale content type", sys.stdout.getvalue())
 </s> add         with captured_stdout() as stdout:
            management.update_contenttypes(self.app_config)
        self.assertIn("Deleting stale content type", stdout.getvalue()) </s> remove         self.old_stdout = sys.stdout
        sys.stdout = StringIO()

    def tearDown(self):
        sys.stdout = self.old_stdout
 </s> add  </s> remove from django.utils.six import StringIO
 </s> add from django.test.utils import captured_stdout </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 from django.utils.six import BytesIO, StringIO
 </s> add from django.test.utils import captured_stderr
from django.utils.six import BytesIO
        with captured_stdout() as stdout:
            management.update_contenttypes(self.app_config, interactive=False)
        self.assertIn("Stale content types remain.", stdout.getvalue())
          """
          non-interactive mode of update_contenttypes() shouldn't delete stale
          content types.
          """
        with captured_stdout() as stdout:
            management.update_contenttypes(self.app_config, interactive=False)
        self.assertIn("Stale content types remain.", stdout.getvalue())
        with captured_stdout() as stdout:
            management.update_contenttypes(self.app_config, interactive=False)
        self.assertIn("Stale content types remain.", stdout.getvalue())
          self.assertEqual(ContentType.objects.count(), self.before_count + 1)
  
  
  class TestRouter(object):
      def db_for_read(self, model, **hints):
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/contenttypes_tests/tests.py