New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing with py.test #197
Comments
|
I'd be impressed if you could unit test a bot that requires an external service as input. |
|
To get the wrapped function from a Command object you use Command.callback (this will be unbound) And you can pass arguments directly in this case. You can also call Command.invoke(ctx) to call the bound method (which is probably what you want.) This will also run any checks bound to the command as well. You would have to build up a Context object and cannot pass arguments directly. e.g Note that in your example, your add command doesn't return anything, it calls bot.say - which is different. Make sure you understand what you're trying to test - testing something like this will require a fair bit of mocking. You'd be better off separating your logic and testing that unit separately, rather than testing commands directly. |
Yeah, that's exactly what I need to do. A momentary lapse of judgement from my part. |
|
Not related to this repo, but someone on the discord just brought this to my attention, might work as a solution for now. I'm going to check it out. |
boy do I have news for you |
klvbdmh commentedMay 3, 2016
I adapted the addition function from examples folder into a class so I could move command functionality into a separate module. It's in
cogs/addition.py:How would I go about testing the
addfunction? I tried the following code:but once I run it I get
TypeError:The text was updated successfully, but these errors were encountered: