From 9c565c67b01833696ac5339ff85a0655310df280 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Fri, 31 Dec 2021 15:46:38 +0100 Subject: [PATCH] Make ComH init error message more precise --- telegram/ext/_commandhandler.py | 2 +- tests/test_commandhandler.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/telegram/ext/_commandhandler.py b/telegram/ext/_commandhandler.py index b3a550f6c24..8de7bb9c40d 100644 --- a/telegram/ext/_commandhandler.py +++ b/telegram/ext/_commandhandler.py @@ -97,7 +97,7 @@ def __init__( self.command = [x.lower() for x in command] for comm in self.command: if not re.match(r'^[\da-z_]{1,32}$', comm): - raise ValueError('Command is not a valid bot command') + raise ValueError(f'Command `{comm}` is not a valid bot command') self.filters = filters if filters is not None else filters_module.UpdateType.MESSAGES diff --git a/tests/test_commandhandler.py b/tests/test_commandhandler.py index 40824a59882..af5ed76f9a0 100644 --- a/tests/test_commandhandler.py +++ b/tests/test_commandhandler.py @@ -173,7 +173,9 @@ def test_basic(self, dp, command): ids=['too long', 'invalid letter', 'invalid characters'], ) def test_invalid_commands(self, cmd): - with pytest.raises(ValueError, match='not a valid bot command'): + with pytest.raises( + ValueError, match=f'`{re.escape(cmd.lower())}` is not a valid bot command' + ): CommandHandler(cmd, self.callback_basic) def test_command_list(self):