Example not working: AttributeError: 'NoneType' object has no attribute 'id'
Edward-Knight opened this issue · 2 comments
Edward-Knight commented
Hi, I can't seem to get this library working. I've taken the example from the readme and made some changes to make it self-contained:
import pytest
from discord.ext import commands
import discord.ext.test as dpytest
@pytest.mark.asyncio
async def test_bot():
bot = commands.Bot(command_prefix="/")
@bot.command()
async def ping(ctx):
await ctx.send("pong")
# Load any extensions/cogs you want to in here
dpytest.configure(bot)
await dpytest.message("/ping")
dpytest.verify_message("pong")
Running on the python:3.8
docker image:
$ pip install pytest dpytest
...
$ pip freeze
aiohttp==3.7.3
async-timeout==3.0.1
attrs==20.3.0
chardet==3.0.4
discord.py==1.6.0
dpytest==0.0.22
idna==3.1
iniconfig==1.1.1
multidict==5.1.0
packaging==20.9
pluggy==0.13.1
py==1.10.0
pyparsing==2.4.7
pytest==6.2.2
pytest-asyncio==0.14.0
toml==0.10.2
typing-extensions==3.7.4.3
yarl==1.6.3
$ pytest testdpy.py
================================================================== test session starts ==================================================================
platform linux -- Python 3.8.7, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /tmp/dpy
plugins: asyncio-0.14.0
collected 1 item
testdpy.py F [100%]
======================================================================= FAILURES ========================================================================
_______________________________________________________________________ test_bot ________________________________________________________________________
@pytest.mark.asyncio
async def test_bot():
bot = commands.Bot(command_prefix="/")
@bot.command()
async def ping(ctx):
await ctx.send("pong")
# Load any extensions/cogs you want to in here
dpytest.configure(bot)
> await dpytest.message("/ping")
testdpy.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/local/lib/python3.8/site-packages/discord/ext/test/runner.py:271: in message
mes = back.make_message(content, member, channel)
/usr/local/lib/python3.8/site-packages/discord/ext/test/backend.py:576: in make_message
data = facts.make_message_dict(
/usr/local/lib/python3.8/site-packages/discord/ext/test/factories.py:221: in make_message_dict
'author': dict_from_user(author),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
user = None
def dict_from_user(user):
out = {
> 'id': user.id,
'username': user.name,
'discriminator': user.discriminator,
'avatar': user.avatar
}
E AttributeError: 'NoneType' object has no attribute 'id'
/usr/local/lib/python3.8/site-packages/discord/ext/test/factories.py:62: AttributeError
------------------------------------------------------------------- Captured log call -------------------------------------------------------------------
WARNING discord.client:client.py:257 PyNaCl is not installed, voice will NOT be supported
================================================================ short test summary info ================================================================
FAILED testdpy.py::test_bot - AttributeError: 'NoneType' object has no attribute 'id'
=================================================================== 1 failed in 0.25s ===================================================================
Any help would be greatly appreciated!
Sergeileduc commented
Currently, this repo doesn't support neither dpy 1.5.1 nor 1.6.0.
You should take a look at the fork from @bravosierra99 (you will find it in the Pull Requests), it supports dpy 1.6.0
Edward-Knight commented
Ah cool, thanks! Downgrading to 1.4 fixed for me 😄
It would be useful the setup.py
was updated to refelct this 👍