-
Notifications
You must be signed in to change notification settings - Fork 24
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
Message queue not empty at test start up #116
Comments
see iScsc#14 on RootPythia's repo as well as iScsc@17b39a0 the commit that introduced this disabled test an issue quzstionning this problem has been opened on dpytest repo CraftSpider/dpytest#116
You are entirely right. We should automatically empty the queue between each test, but I don't have time right now to investigate how to write a teardown |
@ctmbl actually, it works, with our conftest.py ! 😁 we use a cleanup fixture @pytest_asyncio.fixture(autouse=True)
async def cleanup():
yield
await dpytest.empty_queue() Actually the yield is not necessary @pytest_asyncio.fixture(autouse=True)
async def cleanup():
# yield
await dpytest.empty_queue() works just fine. I also try to put the empty queue in the bot fixture yield b
await dpytest.empty_queue() and it works ! So, closing, I guess ? feel free to reopen if you can't make it work. |
oh my bad I didn't see this one, and actually this is how I fixed it: by adding However, using A good solution to me would be to update the documentation to move it after the yield in the bot fixture, this makes sense as this is actually a cleanup after the test. Also, scoping the bot fixture to other scopes than Another really good one would be to implement it by default in I could propose a PR for either solution if you're interested in! |
sure, you can PR with the bot fixture solution ....
yield b
await dpytest.empty_queue() # add a comment to explain why we do that both in conftest.py and in the doc you are probably right, the cleanup fixture is a lot of code, just for 1 line that can be written in the bot fixture. So yeah |
@Sergeileduc could you just reopen this if I open a PR that fix it? |
I don't know if this is a bug or a feature but without explicitly saying it, the message queue is at "module" scope (or even more global) which when using pytest (for example) is really annoying.
I'll illustrate it with the example from dpytest doc (only slightly modified: I renamed the
bot
fixture toconfig_bot
: a weird habit of mine to always rename fixture object in test, feels like functions calls I guess 🤷♂️ )as expected this example pass:
However just modifying a bit
test_ping
(sending two commands) will crashtest_echo
which seems weird: a test shouldn't influence another one:because the AssertionError dump isn't really clear (related to #115) I'll use
dpytest.get_message()
to debug mytest_echo
(the one which has crashed):and we get:
Here we are:
in
test_echo
that doesn't call!ping
tehre is a "Pong !" response in message queueI'm aware of the
dpytest.empty_queue
to clear the message queue, but I'd expect the configuration from dpytest to be fucntion scoped.Ideally I'd like to call this
dpytest.empty_queue
in test teardown: for example after yieldingb
in theconfig_bot
fixture but for some reason an async fixture can't yield and then teardown the test properly, at least I didn't manage to do it 😕I'd really like your thoughts and help on that subject!
The text was updated successfully, but these errors were encountered: