Improve log capturing

This commit is contained in:
Adrian Chaves 2026-06-10 16:39:06 +02:00
parent 712096bf62
commit d0d4b7cd9b
1 changed files with 9 additions and 9 deletions

View File

@ -92,21 +92,21 @@ class TestInternalKeysCheck:
assert "https://source.example.com" in caplog.text
def test_skip_keys_setting(self, caplog: pytest.LogCaptureFixture) -> None:
crawler = get_crawler(Spider, {"META_COPY_WARN_SKIP_KEYS": ["retry_times"]})
mw = MetaCopyDetectionMiddleware.from_crawler(crawler)
req = Request("https://example.com/1", meta={"retry_times": 1})
with caplog.at_level(WARNING):
crawler = get_crawler(Spider, {"META_COPY_WARN_SKIP_KEYS": ["retry_times"]})
mw = MetaCopyDetectionMiddleware.from_crawler(crawler)
req = Request("https://example.com/1", meta={"retry_times": 1})
process(mw, [req])
assert not caplog.records
def test_skip_keys_setting_partial(self, caplog: pytest.LogCaptureFixture) -> None:
crawler = get_crawler(Spider, {"META_COPY_WARN_SKIP_KEYS": ["retry_times"]})
mw = MetaCopyDetectionMiddleware.from_crawler(crawler)
req = Request(
"https://example.com/1",
meta={"retry_times": 1, "redirect_times": 2},
)
with caplog.at_level(WARNING):
crawler = get_crawler(Spider, {"META_COPY_WARN_SKIP_KEYS": ["retry_times"]})
mw = MetaCopyDetectionMiddleware.from_crawler(crawler)
req = Request(
"https://example.com/1",
meta={"retry_times": 1, "redirect_times": 2},
)
process(mw, [req])
assert len(caplog.records) == 1
assert "retry_times" not in caplog.text