From d0d4b7cd9b56bfa098443d1e520274f66cbdfd4c Mon Sep 17 00:00:00 2001 From: Adrian Chaves Date: Wed, 10 Jun 2026 16:39:06 +0200 Subject: [PATCH] Improve log capturing --- tests/test_spidermiddleware_metacopy.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_spidermiddleware_metacopy.py b/tests/test_spidermiddleware_metacopy.py index d137822cf..bfa27ac68 100644 --- a/tests/test_spidermiddleware_metacopy.py +++ b/tests/test_spidermiddleware_metacopy.py @@ -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