1616# under the License.
1717
1818import asyncio
19+ import logging
1920from datetime import datetime , timedelta , timezone
2021from unittest .mock import MagicMock , call , patch
2122
@@ -619,8 +620,10 @@ async def test_no_scroll_id_fast_route(self, async_client, scan_teardown):
619620 scroll_mock .assert_not_called ()
620621 clear_mock .assert_not_called ()
621622
622- @patch ("elasticsearch._async.helpers.logger" )
623- async def test_logger (self , logger_mock , async_client , scan_teardown ):
623+ async def test_logger (
624+ self , caplog : pytest .LogCaptureFixture , async_client , scan_teardown
625+ ):
626+ caplog .set_level (logging .WARNING , logger = "elasticsearch.helpers" )
624627 bulk = []
625628 for x in range (4 ):
626629 bulk .append ({"index" : {"_index" : "test_index" }})
@@ -640,12 +643,16 @@ async def test_logger(self, logger_mock, async_client, scan_teardown):
640643 clear_scroll = False ,
641644 )
642645 ]
643- logger_mock .warning .assert_called ()
644646
647+ assert caplog .messages == [
648+ "Scroll request has only succeeded on 4 (+0 skipped) shards out of 5."
649+ ]
650+
651+ caplog .clear ()
645652 with patch .object (
646653 async_client , "options" , return_value = async_client
647654 ), patch .object (async_client , "scroll" , MockScroll ()):
648- try :
655+ with pytest . raises ( ScanError ) :
649656 _ = [
650657 x
651658 async for x in helpers .async_scan (
@@ -656,14 +663,10 @@ async def test_logger(self, logger_mock, async_client, scan_teardown):
656663 clear_scroll = False ,
657664 )
658665 ]
659- except ScanError :
660- pass
661- logger_mock .warning .assert_called_with (
662- "Scroll request has only succeeded on %d (+%d skipped) shards out of %d." ,
663- 4 ,
664- 0 ,
665- 5 ,
666- )
666+
667+ assert caplog .messages == [
668+ "Scroll request has only succeeded on 4 (+0 skipped) shards out of 5."
669+ ]
667670
668671 async def test_clear_scroll (self , async_client , scan_teardown ):
669672 bulk = []
0 commit comments