Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

BUG: `ctx.create_bot` 未能按预期创建 Bot 对象

オープン
#57 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
testing-qa

調査の方向性

nonebug/mixin/call_api/init.py の ctx.create_bot から始め、nonebot/adapters/console/bot.py に示されている console adapter の Bot.init と比較します。ドキュメントに記載されたテスト例を再現し、fake bot に渡される引数を追跡します。例で報告された AttributeError が発生せずに Bot を作成し、そのアサーションまで続行できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

使用文档中测试平台接口使用的例子

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
主要言語
Python
スター
30
フォーク
7
平均マージ
2日 17時間
マージ済み PR(30日)
1

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nonebot/nonebug のほかの issue

nonebot/nonebug の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。