Skip to content

Commit

Permalink
test: fix test to use max_attempts and Retry-After
Browse files Browse the repository at this point in the history
  • Loading branch information
yolile committed May 30, 2022
1 parent 5ac8b9e commit 554ee71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions kingfisher_scrapy/spiders/portugal_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PortugalBase(LinksSpider):

# Local
# We will wait 1, 2, 4, 8, 16 minutes (31 minutes total).
max_retries = 5
max_attempts = 5
initial_wait_time = 60
# start_url must be provided by subclasses.

Expand All @@ -35,4 +35,4 @@ def parse(self, response):
if self.is_http_success(response) or response.status == 404:
yield from super().parse(response)
else:
yield self.build_retry_request_or_file_error(response, wait_time, self.max_retries, True)
yield self.build_retry_request_or_file_error(response, wait_time, self.max_attempts, True)
7 changes: 4 additions & 3 deletions tests/test_spiders.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def test_start_requests_http_error(spider_name):
callback = request.callback or spider.parse

response = Response('http://example.com', status=555, request=request)
# If `max_retries` is set, the spider handles (and retries) error responses.
if hasattr(spider, 'max_retries'):
response.request.meta['retries'] = spider.max_retries
# If `max_attempts` is set, the spider handles (and retries) error responses.
if hasattr(spider, 'max_attempts'):
response.request.meta['retries'] = spider.max_attempts
response.headers['Retry-After'] = 1
items = list(callback(response))

assert len(items) == 1
Expand Down

0 comments on commit 554ee71

Please sign in to comment.