Collector

The TestCollector Class and some supporting code.

Each test function in the tester bot should be decorated with an instance of TestCollector(), and must have a unique name. The TestCollector() is then passed onto the bot, which runs the tests.


class distest.collector.TestCollector[source]

Used to group tests and pass them around all at once.

Tests can be either added with add or by using @TestCollector to decorate the function, as seen in the sample code below. Is very similar in function to Command from discord.py, which you might already be familiar with.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12

@test_collector()
async def test_reply_contains(interface):
    await interface.assert_reply_contains(
        "Say something containing 'gamer' please!", "gamer"
    )


@test_collector()
async def test_reply_matches(interface):
    await interface.assert_reply_matches(
        "Say something matching the regex `[0-9]{1,3}`", r"[0-9]{1,3}"
add(function, name=None, needs_human=False)[source]

Adds a test function to the group, if one with that name is not already present

Parameters:
  • function (func) – The function to add
  • name (str) – The name of the function to add, defaults to the function name but can be overridden with the provided name just like with discord.ext.commands.Command. See sample code above.
  • needs_human (bool) – Optional boolean, true if the test requires a human interaction
find_by_name(name)[source]

Return the test with the given name, return None if it does not exist.

Parameters:name (str) – The name of the test
Return type:Test, none