Pārlūkot izejas kodu

Test fixes for Issue #3139

Ask Solem 9 gadi atpakaļ
vecāks
revīzija
b516e6f5d0
1 mainītis faili ar 19 papildinājumiem un 14 dzēšanām
  1. 19 14
      celery/tests/tasks/test_result.py

+ 19 - 14
celery/tests/tasks/test_result.py

@@ -20,7 +20,7 @@ from celery.utils import uuid
 from celery.utils.serialization import pickle
 from celery.utils.serialization import pickle
 
 
 from celery.tests.case import (
 from celery.tests.case import (
-    AppCase, Mock, call, depends_on_current_app, patch,
+    AppCase, Mock, call, depends_on_current_app, patch, skip,
 )
 )
 
 
 PYTRACEBACK = """\
 PYTRACEBACK = """\
@@ -219,28 +219,33 @@ class test_AsyncResult(AppCase):
         notb = self.app.AsyncResult(self.task3['id'])
         notb = self.app.AsyncResult(self.task3['id'])
         withtb = self.app.AsyncResult(self.task5['id'])
         withtb = self.app.AsyncResult(self.task5['id'])
 
 
-        self.assertRaises(KeyError, notb.get)
+        with self.assertRaises(KeyError):
+            notb.get()
         try:
         try:
             withtb.get()
             withtb.get()
         except KeyError:
         except KeyError:
             tb  = traceback.format_exc()
             tb  = traceback.format_exc()
             self.assertNotIn('  File "foo.py", line 2, in foofunc', tb)
             self.assertNotIn('  File "foo.py", line 2, in foofunc', tb)
             self.assertNotIn('  File "bar.py", line 3, in barfunc', tb)
             self.assertNotIn('  File "bar.py", line 3, in barfunc', tb)
-            self.assertIn("KeyError: 'blue'", tb)
+            self.assertIn('KeyError:', tb)
+            self.assertIn("'blue'", tb)
         else:
         else:
             raise AssertionError('Did not raise KeyError.')
             raise AssertionError('Did not raise KeyError.')
+
+    @skip.unless_module('tblib')
+    def test_raising_remote_tracebacks(self):
+        old, self.app.conf.remote_tracebacks = (
+            self.app.conf.remote_tracebacks, True)
         try:
         try:
-            old = self.app.conf.remote_tracebacks
-            self.app.conf.remote_tracebacks = True
-            try:
-                withtb.get()
-            except KeyError:
-                tb  = traceback.format_exc()
-                self.assertIn('  File "foo.py", line 2, in foofunc', tb)
-                self.assertIn('  File "bar.py", line 3, in barfunc', tb)
-                self.assertIn("KeyError: 'blue'", tb)
-            else:
-                raise AssertionError('Did not raise KeyError.')
+            withtb.get()
+        except KeyError:
+            tb  = traceback.format_exc()
+            self.assertIn('  File "foo.py", line 2, in foofunc', tb)
+            self.assertIn('  File "bar.py", line 3, in barfunc', tb)
+            self.assertIn('KeyError:', tb)
+            self.assertIn("'blue'", tb)
+        else:
+            raise AssertionError('Did not raise KeyError.')
         finally:
         finally:
             self.app.conf.remote_tracebacks = old
             self.app.conf.remote_tracebacks = old