BUG: `ctx.create_bot` 未能按预期创建 Bot 对象
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 68/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- testing-qa
Línea de trabajo
Comienza con ctx.create_bot en nonebug/mixin/call_api/init.py y compáralo con el Bot.init del adaptador de consola mostrado en nonebot/adapters/console/bot.py. Reproduce el ejemplo de prueba documentado y rastrea los argumentos que se pasan al bot falso. Se considera terminado cuando el ejemplo puede crear un Bot sin el AttributeError reportado y continuar con sus aserciones.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
使用文档中测试平台接口使用的例子
from datetime import datetime
import nonebot
import pytest
from nonebot import on_command
from nonebot.adapters.console import Bot, User, Adapter, Message, MessageEvent
from nonebug import App
from pytest_asyncio import is_async_test
def pytest_collection_modifyitems(items: list[pytest.Item]):
pytest_asyncio_tests = (item for item in items if is_async_test(item))
session_scope_marker = pytest.mark.asyncio(loop_scope='session')
for async_test in pytest_asyncio_tests:
async_test.add_marker(session_scope_marker, append=False)
@pytest.fixture(scope='session', autouse=True)
async def after_nonebot_init(after_nonebot_init: None) -> None:
from nonebot.adapters.console import Adapter as ConsoleAdapter
# 加载适配器
driver = nonebot.get_driver()
driver.register_adapter(ConsoleAdapter)
def make_event(message: str = "") -> MessageEvent:
return MessageEvent(
time=datetime.now(),
self_id="test",
message=Message(message),
user=User(id="user"),
)
@pytest.mark.asyncio
async def test_example(app: App):
foo = on_command("foo")
@foo.handle()
async def _(bot: Bot):
await foo.send("message")
await bot.bell()
async with app.test_matcher(foo) as ctx:
adapter = nonebot.get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter)
event = make_event("/foo")
ctx.receive_event(bot, event)
ctx.should_call_send(event, "message", result=None, bot=bot)
ctx.should_call_api("bell", {}, result=None, adapter=adapter)
异常信息如下:
Launching pytest with arguments var/test_foo.py::test_example --no-header --no-summary -q in C:\Users\Administrator\Project\...
============================= test session starts =============================
collecting ... collected 1 item
======================== 1 failed, 1 warning in 2.74s =========================
var/test_foo.py::test_example FAILED [100%]
var\test_foo.py:46 (test_example)
app = <nonebug.app.App object at 0x000001C524EC7A10>
@pytest.mark.asyncio
async def test_example(app: App):
foo = on_command("foo")
@foo.handle()
async def _(bot: Bot):
await foo.send("message")
await bot.bell()
async with app.test_matcher(foo) as ctx:
adapter = nonebot.get_adapter(Adapter)
> bot = ctx.create_bot(base=Bot, adapter=adapter)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
var\test_foo.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv\Lib\site-packages\nonebug\mixin\call_api\__init__.py:100: in create_bot
bot = make_fake_bot(self, base=base)(adapter, self_id, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <[RecursionError('maximum recursion depth exceeded') raised in repr()] FakeBot object at 0x1c5250e19a0>
adapter = Adapter(name='Console'), info = 'test'
def __init__(self, adapter: "Adapter", info: Robot):
> super().__init__(adapter, info.id)
^^^^^^^
E AttributeError: 'str' object has no attribute 'id'
.venv\Lib\site-packages\nonebot\adapters\console\bot.py:66: AttributeError
- Lenguaje dominante
- Python
- Estrellas
- 30
- Forks
- 7
- Merge medio
- 3 d 5 h
- PR fusionados (30 d)
- 1
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nonebot/nonebug
-
更好的文本差异比较Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
Todos los issues de nonebot/nonebug
Issues similares
-
feedback simulation workshop
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
githubnext/gh-aw-workshop#4455 ·
Los mantenedores suelen responder en 1 día
-
Triage 🩺
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
[BUG] Container scenario crashes without expected_recovery_time, kube DNS example uses retry_waitAbiertoneeds-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
krkn-chaos/krkn#1627 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
NousResearch/hermes-agent#136483 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día