From 8a48d9c6a87211b3424ac7f2714c50915849fac0 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Tue, 9 Jun 2015 04:48:33 +0300 Subject: [PATCH] Ignore ScrapyDeprecationWarning warnings properly. Conflicts: tests/test_utils_deprecate.py --- scrapy/linkextractors/sgml.py | 3 ++- tests/test_selector.py | 9 ++++++--- tests/test_utils_deprecate.py | 16 +++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/scrapy/linkextractors/sgml.py b/scrapy/linkextractors/sgml.py index bae4ad5c0..a9b8fe9de 100644 --- a/scrapy/linkextractors/sgml.py +++ b/scrapy/linkextractors/sgml.py @@ -111,7 +111,8 @@ class SgmlLinkExtractor(FilteringLinkExtractor): tag_func = lambda x: x in tags attr_func = lambda x: x in attrs - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', ScrapyDeprecationWarning) lx = BaseSgmlLinkExtractor(tag=tag_func, attr=attr_func, unique=unique, process_value=process_value) diff --git a/tests/test_selector.py b/tests/test_selector.py index 09dbe6086..ad6a0e21c 100644 --- a/tests/test_selector.py +++ b/tests/test_selector.py @@ -490,21 +490,24 @@ class DeprecatedXpathSelectorTest(unittest.TestCase): self.assertTrue(isinstance(usel, XPathSelector)) def test_xpathselector(self): - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', ScrapyDeprecationWarning) hs = XPathSelector(text=self.text) self.assertEqual(hs.select("//div").extract(), [u'

Hello

']) self.assertRaises(RuntimeError, hs.css, 'div') def test_htmlxpathselector(self): - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', ScrapyDeprecationWarning) hs = HtmlXPathSelector(text=self.text) self.assertEqual(hs.select("//div").extract(), [u'

Hello

']) self.assertRaises(RuntimeError, hs.css, 'div') def test_xmlxpathselector(self): - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', ScrapyDeprecationWarning) xs = XmlXPathSelector(text=self.text) self.assertEqual(xs.select("//div").extract(), [u'

Hello

']) diff --git a/tests/test_utils_deprecate.py b/tests/test_utils_deprecate.py index 41b8100d7..3e7236fb1 100644 --- a/tests/test_utils_deprecate.py +++ b/tests/test_utils_deprecate.py @@ -3,6 +3,7 @@ from __future__ import absolute_import import inspect import unittest import warnings +from scrapy.exceptions import ScrapyDeprecationWarning from scrapy.utils.deprecate import create_deprecated_class, update_classpath from tests import mock @@ -109,7 +110,8 @@ class WarnWhenSubclassedTest(unittest.TestCase): warn_category=MyWarning) # ignore subclassing warnings - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', ScrapyDeprecationWarning) class UserClass(Deprecated): pass @@ -138,7 +140,8 @@ class WarnWhenSubclassedTest(unittest.TestCase): self.assertIn("tests.test_utils_deprecate.Deprecated", msg) def test_issubclass(self): - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', ScrapyDeprecationWarning) DeprecatedName = create_deprecated_class('DeprecatedName', NewName) class UpdatedUserClass1(NewName): @@ -173,7 +176,8 @@ class WarnWhenSubclassedTest(unittest.TestCase): self.assertRaises(TypeError, issubclass, object(), DeprecatedName) def test_isinstance(self): - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', ScrapyDeprecationWarning) DeprecatedName = create_deprecated_class('DeprecatedName', NewName) class UpdatedUserClass2(NewName): @@ -206,7 +210,8 @@ class WarnWhenSubclassedTest(unittest.TestCase): assert not isinstance(OldStyleClass(), DeprecatedName) def test_clsdict(self): - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', ScrapyDeprecationWarning) Deprecated = create_deprecated_class('Deprecated', NewName, {'foo': 'bar'}) self.assertEqual(Deprecated.foo, 'bar') @@ -264,7 +269,8 @@ class UpdateClassPathTest(unittest.TestCase): self.assertIn("scrapy.extensions.debug.Debug", str(w[0].message)) def test_sorted_replacement(self): - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', ScrapyDeprecationWarning) output = update_classpath('scrapy.contrib.pipeline.Pipeline') self.assertEqual(output, 'scrapy.pipelines.Pipeline')