Skip to content

Commit 9aec8de

Browse files
authored
* attempt 'surely this one' on fixing test_idle and test_depr_warnings * remove unused filterwarnings
1 parent ec30266 commit 9aec8de

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

tests/test_animation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def test_send_all_args(self, bot, chat_id, animation_file, animation, thumb_file
104104
assert message.animation.thumb.height == self.height
105105

106106
@flaky(3, 1)
107-
@pytest.mark.filterwarnings("ignore:.*custom attributes")
108107
def test_send_animation_custom_filename(self, bot, chat_id, animation_file, monkeypatch):
109108
def make_assertion(url, data, **kwargs):
110109
return data['animation'].filename == 'custom_filename'

tests/test_bot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ def test_send_chat_action(self, bot, chat_id, chat_action):
717717
bot.send_chat_action(chat_id, 'unknown action')
718718

719719
# TODO: Needs improvement. We need incoming inline query to test answer.
720-
@pytest.mark.filterwarnings("ignore:.*custom attributes")
721720
def test_answer_inline_query(self, monkeypatch, bot):
722721
# For now just test that our internals pass the correct data
723722
def test(url, data, *args, **kwargs):
@@ -970,7 +969,6 @@ def _post(*args, **kwargs):
970969
monkeypatch.delattr(bot, '_post')
971970

972971
# TODO: Needs improvement. No feasible way to test until bots can add members.
973-
@pytest.mark.filterwarnings("ignore:.*custom attributes")
974972
def test_kick_chat_member(self, monkeypatch, bot):
975973
def test(url, data, *args, **kwargs):
976974
chat_id = data['chat_id'] == 2

tests/test_updater.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)