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):