dpytest icon indicating copy to clipboard operation
dpytest copied to clipboard

Verify assert unreadable in failing cases

Open DleanJeans opened this issue 4 years ago • 5 comments

Code:

assert dpytest.verify().message().contains().content(EXPECTED)

Got:

test_unscramble - AssertionError: assert <discord.ext.test.verify.VerifyMessage object at 0x000001693F0B9AF0>

Expected:

test_unscramble - AssertionError: assert 'apparition' in '`opiaripat` → Not found!'

which is from

assert EXPECTED in dpytest.get_message().content

DleanJeans avatar Jun 24 '21 02:06 DleanJeans

I'm not sure if I completely understand your issue here. The new verify builders do make the output a bit more lengthy, but you can still specify a message expression using the standard assert pattern.

assert dpytest.verify().message().contains().content(EXPECTED), f"Missing: {EXPECTED}" Or whatever message you would like.

itsTheFae avatar Jun 24 '21 14:06 itsTheFae

I was expecting the verify builders to automatically output something useful.

This is just shorter while doing the same thing:

assert EXPECTED in get_message().content

vs

assert verify().message().peek().contains().content(EXPECTED), f'`{EXPECTED}` not in `{get_message().content}`'

DleanJeans avatar Jun 25 '21 07:06 DleanJeans

I may be wrong, but CraftSpider might be working on something related to setting or cleaning up the assertion errors. There was mention of a similar issue in the discord server at least.

Since the verify builder returns itself, you can take the lengthy verify call chain and assign it to a variable instead of having the whole chain in the assert. It isn't really less typing for you, but it would keep the lines short and more easy to grok at a glance:

test1 = verify().message().peek().contains().content(EXPECTED)
assert test1, f'`{EXPECTED}` not in `{get_message().content}`'

itsTheFae avatar Jun 25 '21 14:06 itsTheFae

Assigning the variable is an option, I'm working on improving that default assert message. Most likely I'll be making the verify stringify/repr output include details about how the assertion failed, making the assert output look like the desired 'expected/got' without any extra work.

CraftSpider avatar Jun 25 '21 14:06 CraftSpider

Note: The new style is about the same number of characters as the old verify_message for the same result, but both are definitely a bit longer than just assert CONTENT in get_message().content. That pattern is perfectly fine if you don't need the full power of the verifiers, they are specifically designed to simplify complex assertion conditions, and to be extensible to even more advanced conditions in the future (EG, allowing multiple content matches, or asserting thing like information about the user that sent it, or whatever people need out of their message assertions).

CraftSpider avatar Jun 25 '21 14:06 CraftSpider