16
16
# under the License.
17
17
18
18
import asyncio
19
+ import logging
19
20
from datetime import datetime , timedelta , timezone
20
21
from unittest .mock import MagicMock , call , patch
21
22
@@ -619,8 +620,10 @@ async def test_no_scroll_id_fast_route(self, async_client, scan_teardown):
619
620
scroll_mock .assert_not_called ()
620
621
clear_mock .assert_not_called ()
621
622
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" )
624
627
bulk = []
625
628
for x in range (4 ):
626
629
bulk .append ({"index" : {"_index" : "test_index" }})
@@ -640,12 +643,16 @@ async def test_logger(self, logger_mock, async_client, scan_teardown):
640
643
clear_scroll = False ,
641
644
)
642
645
]
643
- logger_mock .warning .assert_called ()
644
646
647
+ assert caplog .messages == [
648
+ "Scroll request has only succeeded on 4 (+0 skipped) shards out of 5."
649
+ ]
650
+
651
+ caplog .clear ()
645
652
with patch .object (
646
653
async_client , "options" , return_value = async_client
647
654
), patch .object (async_client , "scroll" , MockScroll ()):
648
- try :
655
+ with pytest . raises ( ScanError ) :
649
656
_ = [
650
657
x
651
658
async for x in helpers .async_scan (
@@ -656,14 +663,10 @@ async def test_logger(self, logger_mock, async_client, scan_teardown):
656
663
clear_scroll = False ,
657
664
)
658
665
]
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
+ ]
667
670
668
671
async def test_clear_scroll (self , async_client , scan_teardown ):
669
672
bulk = []
0 commit comments