Testing tools

The best code comes with unit tests. Sopel provides a pytest plugin with standard fixtures; factories and mocks to support writing tests; and the rawlist() function to help analyze the mocked-up bot’s output.

sopel.tests

Test tools, factories, pytest fixtures, and mocks.

Added in version 7.0.

sopel.tests.on_message(bot: Sopel, message: str) None

Send the message and wait for all running threads to end.

When triggering plugin callables with bot.on_message Sopel may execute them in their own threads. This is the normal and expected behavior, but it isn’t practical for testing purposes.

This helper function can be used to replace this:

bot.on_message(message)

By this:

from sopel.tests import on_message

on_message(bot, message)

It will automatically join all threads resulting from calling bot.on_message, including potential echo messages.

Added in version 8.1.

See also

A test IRC server can be used instead with its message() method.

sopel.tests.rawlist(*args: str) list[bytes]

Build a list of raw IRC messages from the lines given as *args.

Returns:

a list of raw IRC messages as seen by the bot

Return type:

list

This is a helper function to build a list of messages without having to care about encoding or this pesky carriage return:

>>> rawlist('PRIVMSG :Hello!')
[b'PRIVMSG :Hello!\r\n']