summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-07-24 08:46:29 -0400
committerTim Graham <timograham@gmail.com>2014-07-24 08:46:29 -0400
commit936fba5878075576570ab7d2c84bfba80d183c18 (patch)
tree670f6de2124fefb17af55952027e7e7ba9badbca /tests/contenttypes_tests
parent9b1515906eb28819465276bfa55c6b42c858797d (diff)
Improved patching of sys.stdout in refs #23078.
Diffstat (limited to 'tests/contenttypes_tests')
-rw-r--r--tests/contenttypes_tests/tests.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py
index 1e3a92cc2c..e89d3dcf0d 100644
--- a/tests/contenttypes_tests/tests.py
+++ b/tests/contenttypes_tests/tests.py
@@ -367,19 +367,20 @@ class UpdateContentTypesTests(TestCase):
self.before_count = ContentType.objects.count()
ContentType.objects.create(name='fake', app_label='contenttypes_tests', model='Fake')
self.app_config = apps.get_app_config('contenttypes_tests')
+ self.old_stdout = sys.stdout
+ sys.stdout = StringIO()
+
+ def tearDown(self):
+ sys.stdout = self.old_stdout
def test_interactive_true(self):
"""
interactive mode of update_contenttypes() (the default) should delete
stale contenttypes.
"""
- self.old_stdout = sys.stdout
- sys.stdout = StringIO()
management.input = lambda x: force_str("yes")
management.update_contenttypes(self.app_config)
- output = sys.stdout.getvalue()
- sys.stdout = self.old_stdout
- self.assertIn("Deleting stale content type", output)
+ self.assertIn("Deleting stale content type", sys.stdout.getvalue())
self.assertEqual(ContentType.objects.count(), self.before_count)
def test_interactive_false(self):
@@ -387,12 +388,8 @@ class UpdateContentTypesTests(TestCase):
non-interactive mode of update_contenttypes() shouldn't delete stale
content types.
"""
- self.old_stdout = sys.stdout
- sys.stdout = StringIO()
management.update_contenttypes(self.app_config, interactive=False)
- output = sys.stdout.getvalue()
- sys.stdout = self.old_stdout
- self.assertIn("Stale content types remain.", output)
+ self.assertIn("Stale content types remain.", sys.stdout.getvalue())
self.assertEqual(ContentType.objects.count(), self.before_count + 1)