Skip to content

Testing plugins

Meet Mangukiya edited this page May 29, 2017 · 3 revisions

Using the pytest fixture that errbot provides

errbot provides a pytest fixture that can be used to get a minimal errbot instance to test the errbot functionality.

You push in a message -> you pop a message -> assert the popped message with expected output.

Example:

pytest_plugins = ['errbot.backends.test'] # to load the pytest fixture

def test_function(testbot):
   testbot.push_message(...)
   assert '...' in testbot.pop_message

# testbot is the fixture name. pytest fixtures are used by using the same name as the name of the fixture, then pytest passes the fixture in place of that argument. ;)

Using helper methods in your plugins instead

# Plugin

class Plugin(BotPlugin):

   @botcmd
   def cmd(self, msg, args):
      ...
      # call the helper method appropriately
      Plugin.helper(...)

   @staticmethod
   def helper(...):
      # do something that doesn't require the plugin object
      ...

# PluginTest

import Plugin

def test_plug():
   assert Plugin.helper(...) == ...
Clone this wiki locally