Add testcase for catching exception from open_spider() from pipeline

This commit is contained in:
Paul Tremberth 2016-11-08 11:35:42 +01:00
parent 7727d87f64
commit 61efacdd1f
2 changed files with 23 additions and 0 deletions

11
tests/pipelines.py Normal file
View File

@ -0,0 +1,11 @@
"""
Some pipelines used for testing and benchmarking
"""
class ZeroDivisionErrorPipeline(object):
def open_spider(self, spider):
a = 1/0
def process_item(self, item, spider):
return item

View File

@ -250,6 +250,18 @@ with multiples lines
yield self.assertFailure(crawler.crawl(), TestError)
self.assertFalse(crawler.crawling)
@defer.inlineCallbacks
def test_open_spider_error_on_faulty_pipeline(self):
settings = {
"ITEM_PIPELINES": {
"tests.pipelines.ZeroDivisionErrorPipeline": 300,
}
}
crawler = CrawlerRunner(settings).create_crawler(SimpleSpider)
yield self.assertFailure(
self.runner.crawl(crawler, "http://localhost:8998/status?n=200"),
ZeroDivisionError)
@defer.inlineCallbacks
def test_crawlerrunner_accepts_crawler(self):
crawler = self.runner.create_crawler(SimpleSpider)