Scrapy, a fast high-level web crawling & scraping framework for Python.
Filter test-time warnings. (#6501)
Andrey Rakhmatullin04d0411bf753
diff --git a/tests/test_crawl.py b/tests/test_crawl.pyindex 125709571..1f81a6073 100644--- a/tests/test_crawl.py+++ b/tests/test_crawl.py@@ -428,7 +428,7 @@ with multiples lines@defer.inlineCallbacksdef test_crawl_multiple(self):- runner = CrawlerRunner({"REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7"})+ runner = CrawlerRunner()runner.crawl(SimpleSpider,self.mockserver.url("/status?n=200"),diff --git a/tests/test_crawler.py b/tests/test_crawler.pyindex 69bfb7eb3..92a201fd1 100644--- a/tests/test_crawler.py+++ b/tests/test_crawler.py@@ -6,6 +6,7 @@ import subprocessimport sysimport warningsfrom pathlib import Path+from typing import Anyimport pytestfrom packaging.version import parse as parse_version@@ -28,10 +29,7 @@ from scrapy.utils.spider import DefaultSpiderfrom scrapy.utils.test import get_crawlerfrom tests.mockserver import MockServer, get_mockserver_env-# To prevent warnings.-BASE_SETTINGS = {- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",-}+BASE_SETTINGS: dict[str, Any] = {}def get_raw_crawler(spidercls=None, settings_dict=None):@@ -478,8 +476,6 @@ class CrawlerLoggingTestCase(unittest.TestCase):custom_settings = {"LOG_LEVEL": "INFO","LOG_FILE": str(log_file),- # settings to avoid extra warnings- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",}configure_logging()@@ -582,7 +578,7 @@ class NoRequestsSpider(scrapy.Spider):@mark.usefixtures("reactor_pytest")class CrawlerRunnerHasSpider(unittest.TestCase):def _runner(self):- return CrawlerRunner({"REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7"})+ return CrawlerRunner()@inlineCallbacksdef test_crawler_runner_bootstrap_successful(self):@@ -631,7 +627,6 @@ class CrawlerRunnerHasSpider(unittest.TestCase):CrawlerRunner(settings={"TWISTED_REACTOR": "twisted.internet.asyncioreactor.AsyncioSelectorReactor",- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",})else:@@ -640,7 +635,6 @@ class CrawlerRunnerHasSpider(unittest.TestCase):runner = CrawlerRunner(settings={"TWISTED_REACTOR": "twisted.internet.asyncioreactor.AsyncioSelectorReactor",- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",})yield runner.crawl(NoRequestsSpider)diff --git a/tests/test_downloadermiddleware_offsite.py b/tests/test_downloadermiddleware_offsite.pyindex d4669f450..fec56a39f 100644--- a/tests/test_downloadermiddleware_offsite.py+++ b/tests/test_downloadermiddleware_offsite.py@@ -1,3 +1,5 @@+import warnings+import pytestfrom scrapy import Request, Spider@@ -87,7 +89,9 @@ def test_process_request_invalid_domains():allowed_domains = ["a.example", None, "http:////b.example", "//c.example"]spider = crawler._create_spider(name="a", allowed_domains=allowed_domains)mw = OffsiteMiddleware.from_crawler(crawler)- mw.spider_opened(spider)+ with warnings.catch_warnings():+ warnings.simplefilter("ignore", UserWarning)+ mw.spider_opened(spider)request = Request("https://a.example")assert mw.process_request(request, spider) is Nonefor letter in ("b", "c"):@@ -175,7 +179,9 @@ def test_request_scheduled_invalid_domains():allowed_domains = ["a.example", None, "http:////b.example", "//c.example"]spider = crawler._create_spider(name="a", allowed_domains=allowed_domains)mw = OffsiteMiddleware.from_crawler(crawler)- mw.spider_opened(spider)+ with warnings.catch_warnings():+ warnings.simplefilter("ignore", UserWarning)+ mw.spider_opened(spider)request = Request("https://a.example")assert mw.request_scheduled(request, spider) is Nonefor letter in ("b", "c"):diff --git a/tests/test_dupefilters.py b/tests/test_dupefilters.pyindex f617fc027..9ba8bd64f 100644--- a/tests/test_dupefilters.py+++ b/tests/test_dupefilters.py@@ -50,7 +50,6 @@ class RFPDupeFilterTest(unittest.TestCase):settings = {"DUPEFILTER_DEBUG": True,"DUPEFILTER_CLASS": FromCrawlerRFPDupeFilter,- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",}crawler = get_crawler(settings_dict=settings)scheduler = Scheduler.from_crawler(crawler)@@ -61,7 +60,6 @@ class RFPDupeFilterTest(unittest.TestCase):settings = {"DUPEFILTER_DEBUG": True,"DUPEFILTER_CLASS": FromSettingsRFPDupeFilter,- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",}crawler = get_crawler(settings_dict=settings)scheduler = Scheduler.from_crawler(crawler)@@ -71,7 +69,6 @@ class RFPDupeFilterTest(unittest.TestCase):def test_df_direct_scheduler(self):settings = {"DUPEFILTER_CLASS": DirectDupeFilter,- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",}crawler = get_crawler(settings_dict=settings)scheduler = Scheduler.from_crawler(crawler)@@ -176,7 +173,6 @@ class RFPDupeFilterTest(unittest.TestCase):settings = {"DUPEFILTER_DEBUG": False,"DUPEFILTER_CLASS": FromCrawlerRFPDupeFilter,- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",}crawler = get_crawler(SimpleSpider, settings_dict=settings)spider = SimpleSpider.from_crawler(crawler)@@ -205,7 +201,6 @@ class RFPDupeFilterTest(unittest.TestCase):settings = {"DUPEFILTER_DEBUG": True,"DUPEFILTER_CLASS": FromCrawlerRFPDupeFilter,- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",}crawler = get_crawler(SimpleSpider, settings_dict=settings)spider = SimpleSpider.from_crawler(crawler)@@ -243,7 +238,6 @@ class RFPDupeFilterTest(unittest.TestCase):with LogCapture() as log:settings = {"DUPEFILTER_DEBUG": True,- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",}crawler = get_crawler(SimpleSpider, settings_dict=settings)spider = SimpleSpider.from_crawler(crawler)diff --git a/tests/test_pipeline_crawl.py b/tests/test_pipeline_crawl.pyindex 5cf4a63aa..696ef8cab 100644--- a/tests/test_pipeline_crawl.py+++ b/tests/test_pipeline_crawl.py@@ -71,7 +71,6 @@ class FileDownloadCrawlTestCase(TestCase):# prepare a directory for storing filesself.tmpmediastore = Path(mkdtemp())self.settings = {- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7","ITEM_PIPELINES": {self.pipeline_class: 1},self.store_setting_key: str(self.tmpmediastore),}diff --git a/tests/test_scheduler.py b/tests/test_scheduler.pyindex 6b7cd5dac..387bc7c20 100644--- a/tests/test_scheduler.py+++ b/tests/test_scheduler.py@@ -53,7 +53,6 @@ class MockCrawler(Crawler):"SCHEDULER_PRIORITY_QUEUE": priority_queue_cls,"JOBDIR": jobdir,"DUPEFILTER_CLASS": "scrapy.dupefilters.BaseDupeFilter",- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",}super().__init__(Spider, settings)self.engine = MockEngine(downloader=MockDownloader())diff --git a/tests/test_spiderloader/__init__.py b/tests/test_spiderloader/__init__.pyindex 32699d837..d2ff9ba48 100644--- a/tests/test_spiderloader/__init__.py+++ b/tests/test_spiderloader/__init__.py@@ -103,7 +103,6 @@ class SpiderLoaderTest(unittest.TestCase):runner = CrawlerRunner({"SPIDER_MODULES": [module],- "REQUEST_FINGERPRINTER_IMPLEMENTATION": "2.7",})diff --git a/tests/test_utils_asyncio.py b/tests/test_utils_asyncio.pyindex 65e352053..1c93829e9 100644--- a/tests/test_utils_asyncio.py+++ b/tests/test_utils_asyncio.py@@ -1,8 +1,8 @@import asyncioimport warnings-from unittest import TestCasefrom pytest import mark+from twisted.trial.unittest import TestCasefrom scrapy.utils.defer import deferred_f_from_coro_ffrom scrapy.utils.reactor import (diff --git a/tests/test_utils_datatypes.py b/tests/test_utils_datatypes.pyindex fb7c90f80..10dc6f270 100644--- a/tests/test_utils_datatypes.py+++ b/tests/test_utils_datatypes.py@@ -3,6 +3,8 @@ import unittestimport warningsfrom collections.abc import Iterator, Mapping, MutableMapping+import pytest+from scrapy.exceptions import ScrapyDeprecationWarningfrom scrapy.http import Requestfrom scrapy.utils.datatypes import (@@ -90,12 +92,14 @@ class CaseInsensitiveDictMixin:self.assertRaises(KeyError, d.__getitem__, "key_LOWER")self.assertRaises(KeyError, d.__getitem__, "key_lower")+ @pytest.mark.filterwarnings("ignore::scrapy.exceptions.ScrapyDeprecationWarning")def test_getdefault(self):d = CaselessDict()self.assertEqual(d.get("c", 5), 5)d["c"] = 10self.assertEqual(d.get("c", 5), 10)+ @pytest.mark.filterwarnings("ignore::scrapy.exceptions.ScrapyDeprecationWarning")def test_setdefault(self):d = CaselessDict({"a": 1, "b": 2})@@ -212,11 +216,13 @@ class CaseInsensitiveDictTest(CaseInsensitiveDictMixin, unittest.TestCase):self.assertEqual(list(iterkeys), ["AsDf", "FoO"])[email protected]("ignore::scrapy.exceptions.ScrapyDeprecationWarning")class CaselessDictTest(CaseInsensitiveDictMixin, unittest.TestCase):dict_class = CaselessDictdef test_deprecation_message(self):with warnings.catch_warnings(record=True) as caught:+ warnings.filterwarnings("always", category=ScrapyDeprecationWarning)self.dict_class({"foo": "bar"})self.assertEqual(len(caught), 1)diff --git a/tests/test_utils_misc/__init__.py b/tests/test_utils_misc/__init__.pyindex ee3314d8e..4d8e71521 100644--- a/tests/test_utils_misc/__init__.py+++ b/tests/test_utils_misc/__init__.py@@ -4,6 +4,8 @@ import unittestfrom pathlib import Pathfrom unittest import mock+import pytest+from scrapy.item import Field, Itemfrom scrapy.utils.misc import (arg_to_iter,@@ -97,6 +99,7 @@ class UtilsMiscTestCase(unittest.TestCase):list(arg_to_iter(TestItem(name="john"))), [TestItem(name="john")])+ @pytest.mark.filterwarnings("ignore::scrapy.exceptions.ScrapyDeprecationWarning")def test_create_instance(self):settings = mock.MagicMock()crawler = mock.MagicMock(spec_set=["settings"])