Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

[test] Handle keyword args in CrawlSpider.parse

Eugenio Lacuestac54df8253a67
diff --git a/tests/spiders.py b/tests/spiders.py
index dcc475ca7..c042eb7fe 100644
--- a/tests/spiders.py
+++ b/tests/spiders.py
@@ -211,8 +211,9 @@ class CrawlSpiderWithParseMethod(MockServerSpider, CrawlSpider):
url = self.mockserver.url("/alpayload")
yield Request(url, method="POST", body=test_body)
- def parse(self, response):
- self.logger.info('[parse] status %i', response.status)
+ def parse(self, response, foo=None):
+ self.logger.info('[parse] status %i (foo: %s)', response.status, foo)
+ yield Request(self.mockserver.url("/status?n=202"), self.parse, cb_kwargs={"foo": "bar"})
class CrawlSpiderWithErrback(CrawlSpiderWithParseMethod):
diff --git a/tests/test_crawl.py b/tests/test_crawl.py
index 4299e4bbb..6247ced35 100644
--- a/tests/test_crawl.py
+++ b/tests/test_crawl.py
@@ -316,8 +316,9 @@ class CrawlSpiderTestCase(TestCase):
with LogCapture() as log:
yield self.runner.join()
- self.assertIn("[parse] status 200", str(log))
- self.assertIn("[parse] status 201", str(log))
+ self.assertIn("[parse] status 200 (foo: None)", str(log))
+ self.assertIn("[parse] status 201 (foo: None)", str(log))
+ self.assertIn("[parse] status 202 (foo: bar)", str(log))
@defer.inlineCallbacks
def test_crawlspider_with_errback(self):
@@ -326,8 +327,9 @@ class CrawlSpiderTestCase(TestCase):
with LogCapture() as log:
yield self.runner.join()
- self.assertIn("[parse] status 200", str(log))
- self.assertIn("[parse] status 201", str(log))
+ self.assertIn("[parse] status 200 (foo: None)", str(log))
+ self.assertIn("[parse] status 201 (foo: None)", str(log))
+ self.assertIn("[parse] status 202 (foo: bar)", str(log))
self.assertIn("[errback] status 404", str(log))
self.assertIn("[errback] status 500", str(log))
self.assertIn("[errback] status 501", str(log))