【发布时间】:2021-04-23 09:27:35
【问题描述】:
编写单元测试/Pytests
我有一个不和谐的机器人,我正在尝试为它编写测试。我尝试了一个名为 distest 的库,它在某些方面效果很好,但不是全部..
我有第二个机器人发送消息并检查响应,但它不能与 Unittests 或 Pytest 一起使用。
这是我的一项测试的示例, 它正在检查回复“Pong!”如果发送了“ping”。
我在使用 pytest 调用脚本之前运行需要测试的机器人
from discord.ext import commands
from dotenv import load_dotenv
import os
import pytest
TOKEN = "bot token of tester bot"
bot = commands.Bot(command_prefix='?/')
bot.run(TOKEN)
target_id = "ID of bot to be tested"
channel_id = "ID of channel of where it will be tested"
async def test_ping():
correct_response = 'Pong!'
channel = await bot.fetch_channel(channel_id)
await channel.send("ping")
def check(m):
return m.content == correct_response and m.author.id == target_id
response = await bot.wait_for('message', check=check)
assert (response.content == correct_response)
Pytests 卡在收集上,当我尝试 Unittests 时,它只是挂起,什么也没做
【问题讨论】:
标签: python discord.py pytest