Factories#

Test factories: they create objects for testing purposes.

New in version 7.0.

class sopel.tests.factories.BotFactory#

Factory to create bot.

See also

The botfactory() fixture can be used to instantiate this factory.

preloaded(
settings: config.Config,
preloads: Iterable[str] | None = None,
) bot.Sopel#

Create a bot and preload its plugins.

Parameters:
  • settings (sopel.config.Config) – Sopel’s configuration for testing purposes

  • preloads (list) – list of plugins to preload, setup, and register

Returns:

a test instance of the bot

Return type:

sopel.bot.Sopel

This will instantiate a Sopel object, replace its backend with a MockIRCBackend, and then preload plugins. This will automatically load the coretasks plugin, and every other plugin from preloads:

factory = BotFactory()
bot = factory.preloaded(settings, ['emoticons', 'remind'])

Note

This will automatically setup plugins: be careful with plugins that require access to external services on setup.

You may also need to manually call shutdown routines for the loaded plugins.

class sopel.tests.factories.ConfigFactory(tmpdir)#

Factory to create settings.

See also

The configfactory() fixture can be used to instantiate this factory.

class sopel.tests.factories.IRCFactory#

Factory to create mock IRC server.

See also

The ircfactory() fixture can be used to create this factory.

class sopel.tests.factories.TriggerFactory#

Factory to create trigger.

See also

The triggerfactory() fixture can be used to instantiate this factory.

class sopel.tests.factories.UserFactory#

Factory to create mock user.

See also

The userfactory() fixture can be used to create this factory.