浏览代码

Silences an error printed to stderr when running unittests

Ask Solem 13 年之前
父节点
当前提交
661b7f52c3
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      celery/tests/test_bin/__init__.py

+ 6 - 3
celery/tests/test_bin/__init__.py

@@ -4,7 +4,7 @@ from __future__ import with_statement
 import os
 
 from celery.bin.base import Command
-from celery.tests.utils import AppCase
+from celery.tests.utils import AppCase, override_stdouts
 
 
 class Object(object):
@@ -55,8 +55,11 @@ class test_Command(AppCase):
     def test_with_bogus_args(self):
         cmd = MockCommand()
         cmd.supports_args = False
-        self.assertRaises(SystemExit,
-                cmd.execute_from_commandline, argv=["--bogus"])
+        with override_stdouts() as (_, stderr):
+            with self.assertRaises(SystemExit):
+                cmd.execute_from_commandline(argv=["--bogus"])
+        self.assertTrue(stderr.getvalue())
+        self.assertIn("Unrecognized", stderr.getvalue())
 
     def test_with_custom_config_module(self):
         prev = os.environ.pop("CELERY_CONFIG_MODULE", None)