Skip to content

Add better AssertionError messages when using dpytest.verify() #115

@ctmbl

Description

@ctmbl

Is your feature request related to a problem? Please describe.

When writing my tests I need to debug why an AssertionError is raised when verifying a message. I can't know what message is being verified so I can't debug the bot/cog.

Describe the solution you'd like

A clear diff between the expected message content (passed as parameter) and the message sent by the bot, as pytest/python do:

>       assert ret_user.username == "dummy"
E       AssertionError: assert 'dumy' == 'dummy'
E         - dumy
E         + dummy
E         ?  +

tests/test_dummy_db_manager.py:17: AssertionError

Describe alternatives you've considered

Currently it looks like:

E       assert <discord.ext.test.verify.VerifyMessage object at 0x7fe857f5d840>
E        +  where <discord.ext.test.verify.VerifyMessage object at 0x7fe857f5d840> = <bound method VerifyMessage.content of <discord.ext.test.verify.VerifyMessage object at 0x7fe857f5d840>>("isn't in the database")
E        +    where <bound method VerifyMessage.content of <discord.ext.test.verify.VerifyMessage object at 0x7fe857f5d840>> = <discord.ext.test.verify.VerifyMessage object at 0x7fe857f5d840>.content
E        +      where <discord.ext.test.verify.VerifyMessage object at 0x7fe857f5d840> = <bound method VerifyMessage.contains of <discord.ext.test.verify.VerifyMessage object at 0x7fe857f5d840>>()
E        +        where <bound method VerifyMessage.contains of <discord.ext.test.verify.VerifyMessage object at 0x7fe857f5d840>> = <discord.ext.test.verify.VerifyMessage object at 0x7fe857f5d840>.contains
E        +          where <discord.ext.test.verify.VerifyMessage object at 0x7fe857f5d840> = <bound method Verify.message of <discord.ext.test.verify.Verify object at 0x7fe857f5dd50>>()
E        +            where <bound method Verify.message of <discord.ext.test.verify.Verify object at 0x7fe857f5dd50>> = <discord.ext.test.verify.Verify object at 0x7fe857f5dd50>.message
E        +              where <discord.ext.test.verify.Verify object at 0x7fe857f5dd50> = <function verify at 0x7fe8582cab90>()
E        +                where <function verify at 0x7fe8582cab90> = dpytest.verify

Maybe at least writing a better __str__ or __repr__ for the Verify* classes could be a solution

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions