Failing at Unit Testing

14 views
Skip to first unread message

j3b

unread,
Feb 10, 2021, 9:38:38 PM2/10/21
to Evennia
As an exercise, in order to try to better understand how to make good use of unit testing, I copied just the following code from the built-in evennia tests and put it into my own test module under the "commands" directory.

class TestAccount(CommandTest):
    """Emulate the built-in test"""
    def test_ooc(self):
        self.call(account.CmdOOC(), "", "You go OOC.", caller=self.account)

    def test_ic(self):
        self.account.db._playable_characters = [self.char1]
        self.account.unpuppet_object(self.session)
        self.call(
                 account.CmdIC(), "Obj", "You become Char.",
                 caller=self.account,
                 receiver=self.char1)

The first test "ooc" works but the second fails as follows.

AssertionError:
=================Wanted message=======================
You become Char.
 ================Returned message======================

======================================================

In game (using my own db) however both commands work as expected:

>ooc

You go OOC.

You are out-of-character (OOC).
Use ic to get back into the game.
>ic

You become Char.

All this is to say I feel stumped. If I can't even get built in tests to work as expected I an a long way from being able to test my custom commands.  I don't suppose this is a problem with the testing suite but a problem of my own understanding.  However I'm really not sure where to go from here.  Any advice, whether general or particular would be appreciated.

Thanks

Zude Onim

unread,
Feb 10, 2021, 11:39:48 PM2/10/21
to eve...@googlegroups.com
Is your test command part of a command set ?
> --
> You received this message because you are subscribed to the Google Groups
> "Evennia" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to evennia+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/evennia/999a476d-2cd8-4611-a16c-363e795cc8f7n%40googlegroups.com.
>

Griatch Art

unread,
Feb 11, 2021, 3:58:12 AM2/11/21
to Evennia
@j3b

This looks like a typo. This is what you have:

self.call(
                 account.CmdIC(), "Obj", "You become Char.",
                 caller=self.account,
                 receiver=self.char1)

Note that you are trying to puppet "Obj", but the `receiver` is set to self.char1. It's the receiver which will mocked to receive the output message you are looking for ("You become X").
It's a little special for `ic` since the receiver changes from Account to Char mid-command. Usually the caller of the commandis the same one that should receive the output of it, so
`receiver` is not necessary to specify. But even so, you are trying to puppet Obj but is checking for a return string about you puppeting Char, soeven with the right receiver you'd get an error.

The original code is actually this:

self.call(
                 account.CmdIC(), "Char", "You become Char.",
                 caller=self.account,
                 receiver=self.char1)

which passes. For some reason you swapped "Char" for "Obj" when you copied it over into your code, which is why your version does not pass.
.
Griatch
Reply all
Reply to author
Forward
0 new messages