🐛 fix parent detect error after require (#1121)

This commit is contained in:
Ju4tCode
2022-08-04 13:39:20 +08:00
committed by GitHub
parent 48ccef2f06
commit 2192e8cb6d
8 changed files with 54 additions and 27 deletions

View File

@ -1,6 +1,13 @@
from pathlib import Path
import nonebot
from nonebot.plugin import PluginManager, _managers
_sub_plugins = set()
_sub_plugins |= nonebot.load_plugins(str((Path(__file__).parent / "plugins").resolve()))
manager = PluginManager(
search_path=[str((Path(__file__).parent / "plugins").resolve())]
)
_managers.append(manager)
# test load nested plugin with require
manager.load_plugin("nested_subplugin")
manager.load_plugin("nested_subplugin2")

View File

@ -0,0 +1 @@
from .nested_subplugin2 import a

View File

@ -0,0 +1 @@
a = "required by another subplugin"

View File

@ -38,6 +38,19 @@ async def test_load_plugin(app: App, load_plugin: Set["Plugin"]):
assert nonebot.load_plugin("some_plugin_not_exist") is None
@pytest.mark.asyncio
async def test_load_nested_plugin(app: App, load_plugin: Set["Plugin"]):
import nonebot
parent_plugin = nonebot.get_plugin("nested")
sub_plugin = nonebot.get_plugin("nested_subplugin")
sub_plugin2 = nonebot.get_plugin("nested_subplugin2")
assert parent_plugin and sub_plugin and sub_plugin2
assert sub_plugin.parent_plugin is parent_plugin
assert sub_plugin2.parent_plugin is parent_plugin
assert parent_plugin.sub_plugins == {sub_plugin, sub_plugin2}
@pytest.mark.asyncio
async def test_bad_plugin(app: App):
import nonebot