Close the file in test_stats_file_failed().

This commit is contained in:
Andrey Rakhmatullin 2026-06-22 23:17:59 +05:00
parent a7a3ef39ba
commit 0d9147ea85
1 changed files with 6 additions and 1 deletions

View File

@ -478,9 +478,14 @@ class TestFeedExport(TestFeedExportBase):
},
}
crawler = get_crawler(ItemSpider, settings)
def store(file: IO[bytes]) -> None:
file.close()
raise KeyError("foo")
with mock.patch(
"scrapy.extensions.feedexport.FileFeedStorage.store",
side_effect=KeyError("foo"), # TODO this needs file.close()
side_effect=store,
):
yield crawler.crawl(mockserver=self.mockserver)
assert "feedexport/failed_count/FileFeedStorage" in crawler.stats.get_stats()