Sergey Schetinin avatar Sergey Schetinin committed f2fa749

attempt to silence deprecation warnings during testing

Comments (0)

Files changed (5)

docs/test_request.txt

 This demonstrates how the Request object works, and tests it.
 
-To test for absense of PendingDeprecationWarning's we should reset
-default warning filters
-
-    >>> import warnings
-    >>> warnings.resetwarnings()
-
-
 You can instantiate a request using ``Request.blank()``, to create a
 fresh environment dictionary with all the basic keys such a dictionary
 should have.

tests/test_misc.py

     eq(ub.getall('key'), [u'\xf8'])
     eq(repr(ub.getall('fs')), "[FieldStorage(None, u'\\xf8', [])]")
 
-def test_multidict_update_warning():
-    fcapture = StringIO()
-    stderr, sys.stderr = sys.stderr, fcapture
-
-    # test warning when duplicate keys are passed
-    r = Response()
-    r.headers.update([
-        ('Set-Cookie', 'a=b'),
-        ('Set-Cookie', 'x=y'),
-    ])
-    fcapture.seek(0)
-    assert 'Consider using .extend()' in fcapture.readline()
-
-    # but no warning on normal operation
-    fcapture.seek(0)
-    fcapture.truncate()
-    r.headers.update([('Set-Cookie', 'a=b')])
-    assert not fcapture.getvalue()
-
-    sys.stderr = stderr

tests/test_request.py

 
 _marker = object()
 
+warnings.showwarning = lambda *args, **kw: None
+
 class BaseRequestTests(unittest.TestCase):
     def _makeStringIO(self, text):
         try:

tests/test_util.py

 import unittest
+from webob import Request, Response
 
 class Test_warn_deprecation(unittest.TestCase):
     def setUp(self):
         self.assertEqual(deprecation_warning['type'], DeprecationWarning)
 
     def test_decode_param_names_attr(self):
-        from webob import Request
         class BadRequest(Request):
             decode_param_names = False
         req = BadRequest.blank('?a=b')
         self.assertEqual(len(self.warnings), 1)
         deprecation_warning = self.warnings[0]
         self.assertEqual(deprecation_warning['type'], DeprecationWarning)
+
+    def test_multidict_update_warning(self):
+        # test warning when duplicate keys are passed
+        r = Response()
+        r.headers.update([
+            ('Set-Cookie', 'a=b'),
+            ('Set-Cookie', 'x=y'),
+        ])
+        self.assertEqual(len(self.warnings), 1)
+        deprecation_warning = self.warnings[0]
+        self.assertEqual(deprecation_warning['type'], UserWarning)
+        assert 'Consider using .extend()' in deprecation_warning['text']
+
+    def test_multidict_update_warning_unnecessary(self):
+        # no warning on normal operation
+        r = Response()
+        r.headers.update([('Set-Cookie', 'a=b')])
+        self.assertEqual(len(self.warnings), 0)

webob/multidict.py

                 msg = ("Behavior of MultiDict.update() has changed "
                     "and overwrites duplicate keys. Consider using .extend()"
                 )
-                warnings.warn(msg, stacklevel=2)
+                warnings.warn(msg, UserWarning, stacklevel=2)
         DictMixin.update(self, *args, **kw)
 
     def extend(self, other=None, **kwargs):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.