CraftSpider/dpytest

Unclear error message

LeCuay opened this issue · 4 comments

When testing (for example) if an embed matches what it's expected the error it's nested and doesn't give clear information about what went wrong.

For example I have this test:

@pytest.mark.asyncio
async def test_roll_ok(bot):
    roll = f'{bot.command_prefix}roll 20'
    expected_embed = discord.Embed(
        title=f'Roll *{roll}*',
        description='You rolled **20**.',
    )
    expected_embed.set_footer(text='20: [20]')
    await dpytest.message(content=roll)

    assert dpytest.verify().message().embed(expected_embed), 'Wrong embed sent'

roll 20 will return 20 since is not rolling a dice making a sum

The returned error is:

E       AssertionError: Wrong embed sent
E       assert <discord.ext.test.verify.VerifyMessage object at 0x7f39d58af7f0>
E        +  where <discord.ext.test.verify.VerifyMessage object at 0x7f39d58af7f0> = <bound method VerifyMessage.embed of <discord.ext.test.verify.VerifyMessage object at 0x7f39d58af7f0>>(<discord.embeds.Embed object at 0x7f39d9e70310>)
E        +    where <bound method VerifyMessage.embed of <discord.ext.test.verify.VerifyMessage object at 0x7f39d58af7f0>> = <discord.ext.test.verify.VerifyMessage object at 0x7f39d58af7f0>.embed
E        +      where <discord.ext.test.verify.VerifyMessage object at 0x7f39d58af7f0> = <bound method Verify.message of <discord.ext.test.verify.Verify object at 0x7f39d58af130>>()
E        +        where <bound method Verify.message of <discord.ext.test.verify.Verify object at 0x7f39d58af130>> = <discord.ext.test.verify.Verify object at 0x7f39d58af130>.message
E        +          where <discord.ext.test.verify.Verify object at 0x7f39d58af130> = <function verify at 0x7f39d6129670>()
E        +            where <function verify at 0x7f39d6129670> = dpytest.verify

I don't have a text of what didn't match or what did happen. How can this be tested correctly?

I have the same issue.

E       AssertionError: assert <discord.ext.test.verify.VerifyMessage object at 0x12e0f7700>
E        +  where <discord.ext.test.verify.VerifyMessage object at 0x12e0f7700> = <bound method VerifyMessage.content of <discord.ext.test.verify.VerifyMessage object at 0x12e0f7700>>('what the absolute fuck')
E        +    where <bound method VerifyMessage.content of <discord.ext.test.verify.VerifyMessage object at 0x12e0f7700>> = <discord.ext.test.verify.VerifyMessage object at 0x12e0f7700>.content
E        +      where <discord.ext.test.verify.VerifyMessage object at 0x12e0f7700> = <bound method Verify.message of <discord.ext.test.verify.Verify object at 0x12e0f77f0>>()
E        +        where <bound method Verify.message of <discord.ext.test.verify.Verify object at 0x12e0f77f0>> = <discord.ext.test.verify.Verify object at 0x12e0f77f0>.message
E        +          where <discord.ext.test.verify.Verify object at 0x12e0f77f0> = <function verify at 0x12935a200>()
E        +            where <function verify at 0x12935a200> = dpytest.verify

Why doesn't this show expected vs actual?

Also, does dpytest trap output and not forward it when there's an AssertionError or something? I can't print in my code to debug (I have --capture=no for pytest and can see print statements when there ISN'T an AssertionError), and the debugger is skipping debug points when there's an AssertionError only it seems.

And the bot works, I'm testing it out manually as well. I'm just trying to add a simple test for something I can see is working.

I don't think there is a capture thing in dpytest no.

So it must come from pytest directy, I don't really know.

But for all that, it's more Cratspyder thing, sorry.

The problem is that :
the thing after assert is a boolean. It's just true or false, that's it. No information more.

So, what we can do, is:
put the error message, in the tests (but not in the library, it's on the user side)
to display the errors.

Maybe we could write some functions, to do that

for a message, what I do is :

    await channel.send("Test Message")
    mess = dpytest.get_message(peek=True)  # peek doesnt remove the message from the queue, important for verify after
    expected = "Test Message foo"
    assert dpytest.verify().message().content(expected), "%s != %s" % (mess.content, expected)

But yeah, maybe we can write some "easy to use" functions that implement that, I don't know

Feel free to propose some PRs