mirror of https://github.com/scrapy/scrapy.git
Fix output file overwrite with -O (FeedExporter updated) (#4859)
This commit is contained in:
parent
75f35f558f
commit
a5872a0fad
|
|
@ -452,7 +452,7 @@ class FeedExporter:
|
|||
crawler = getattr(self, 'crawler', None)
|
||||
|
||||
def build_instance(builder, *preargs):
|
||||
return build_storage(builder, uri, preargs=preargs)
|
||||
return build_storage(builder, uri, feed_options=feed_options, preargs=preargs)
|
||||
|
||||
if crawler and hasattr(feedcls, 'from_crawler'):
|
||||
instance = build_instance(feedcls.from_crawler, crawler)
|
||||
|
|
|
|||
|
|
@ -680,9 +680,14 @@ class MySpider(scrapy.Spider):
|
|||
)
|
||||
return []
|
||||
"""
|
||||
with open(os.path.join(self.cwd, "example.json"), "w") as f1:
|
||||
f1.write("not empty")
|
||||
args = ['-O', 'example.json']
|
||||
log = self.get_log(spider_code, args=args)
|
||||
self.assertIn('[myspider] DEBUG: FEEDS: {"example.json": {"format": "json", "overwrite": true}}', log)
|
||||
with open(os.path.join(self.cwd, "example.json")) as f2:
|
||||
first_line = f2.readline()
|
||||
self.assertNotEqual(first_line, "not empty")
|
||||
|
||||
def test_output_and_overwrite_output(self):
|
||||
spider_code = """
|
||||
|
|
@ -813,9 +818,14 @@ class MySpider(scrapy.Spider):
|
|||
)
|
||||
return []
|
||||
"""
|
||||
with open(os.path.join(self.cwd, "example.json"), "w") as f1:
|
||||
f1.write("not empty")
|
||||
args = ['-O', 'example.json']
|
||||
log = self.get_log(spider_code, args=args)
|
||||
self.assertIn('[myspider] DEBUG: FEEDS: {"example.json": {"format": "json", "overwrite": true}}', log)
|
||||
with open(os.path.join(self.cwd, "example.json")) as f2:
|
||||
first_line = f2.readline()
|
||||
self.assertNotEqual(first_line, "not empty")
|
||||
|
||||
def test_output_and_overwrite_output(self):
|
||||
spider_code = """
|
||||
|
|
|
|||
Loading…
Reference in New Issue