@@ -504,8 +504,13 @@ def test_deprecation_warnings_start_webhook(self, recwarn, updater, monkeypatch)
504504 updater .start_webhook (ip , port , clean = True , force_event_loop = False )
505505 updater .stop ()
506506
507- for warning in recwarn .list :
508- print (warning .message )
507+ for warning in recwarn :
508+ print (warning )
509+
510+ try : # This is for flaky tests (there's an unclosed socket sometimes)
511+ recwarn .pop (ResourceWarning ) # internally iterates through recwarn.list and deletes it
512+ except AssertionError :
513+ pass
509514
510515 assert len (recwarn ) == 3
511516 assert str (recwarn [0 ].message ).startswith ('Old Handler API' )
@@ -523,6 +528,12 @@ def test_clean_deprecation_warning_polling(self, recwarn, updater, monkeypatch):
523528 updater .stop ()
524529 for msg in recwarn :
525530 print (msg )
531+
532+ try : # This is for flaky tests (there's an unclosed socket sometimes)
533+ recwarn .pop (ResourceWarning ) # internally iterates through recwarn.list and deletes it
534+ except AssertionError :
535+ pass
536+
526537 assert len (recwarn ) == 2
527538 assert str (recwarn [0 ].message ).startswith ('Old Handler API' )
528539 assert str (recwarn [1 ].message ).startswith ('The argument `clean` of' )
@@ -621,10 +632,17 @@ def test_idle(self, updater, caplog):
621632
622633 # There is a chance of a conflict when getting updates since there can be many tests
623634 # (bots) running simultaneously while testing in github actions.
624- for idx , log in enumerate (caplog .records ):
625- if log .getMessage ().startswith ('Error while getting Updates: Conflict' ):
635+ records = caplog .records .copy () # To avoid iterating and removing at same time
636+ for idx , log in enumerate (records ):
637+ print (log )
638+ msg = log .getMessage ()
639+ if msg .startswith ('Error while getting Updates: Conflict' ):
626640 caplog .records .pop (idx ) # For stability
627- assert len (caplog .records ) == 2 , caplog .records
641+
642+ if msg .startswith ('No error handlers are registered' ):
643+ caplog .records .pop (idx )
644+
645+ assert len (caplog .records ) == 2 , caplog .records
628646
629647 rec = caplog .records [- 2 ]
630648 assert rec .getMessage ().startswith (f'Received signal { signal .SIGTERM } ' )
0 commit comments