-
-
Notifications
You must be signed in to change notification settings - Fork 343
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
Is there a unittest adapter like asynctest for trio? #838
Comments
There isn't currently any standard unittest/trio integration. It would be great if there were! As you correctly guessed, the idea of So you have a few options:
If you say a bit more about how you're using asynctest and what your goals are (e.g. are you trying to avoid pytest for some reason?), then we might be able to say more. Also, what happened when you used |
Wow, thanks for the elaborate response. I love pytest and I'm currently running my unittest suite via pytest. So, pytest-trio would be my favourite way. Here is an example test:
Would result in:
I think going for a simple wrapper class like asynctest would be my preferred way, too. I'll look into. |
Hmm. I suspect I only wrote
...but if you're using pytest, then probably you're going to be better off getting pytest-trio working, instead of messing with Unfortunately, it looks like right now pytest-trio can't automatically make async unittest testcases work. I tried enabling trio-mode and using this test file: # test_demo_1.py
import unittest
import trio
class TestDemo(unittest.TestCase):
async def test_demo(self):
await trio.sleep(1) ...and it didn't work, I got:
This means it didn't actually run the test. (Notice that it finished in "0.02 seconds", so it clearly didn't do I suspect that pytest lets But, if I write it as a pytest test class, by simply deleting the base class: # test_demo_2.py
import trio
class TestDemo: # notice: no longer inherits from unittest.TestCase
async def test_demo(self):
await trio.sleep(1) And now it works fine:
So if your end goal is to run everything with pytest, then one option is to migrate away from unittest entirely – and depending on how heavily you're using unittest features, it might be pretty easy as well. If that's not viable, then I guess the next best thing would be to figure out if we can make pytest-trio handle unittest-based test cases. What do you think? |
FWIW, "move away from it" is what I habitually do with unittest. The most annoying part is to replace all these |
There's no particular urgency to replacing the There's also this tool that claims to do it automatically, though I haven't tried it myself: https://github.com/pytest-dev/unittest2pytest |
Except if you no longer inherit from |
@smurfix haha wow you're right of course. I guess that shows how out-of-touch I am with So I guess converting away from unittest is harder than I realized. Well, I opened an issue at pytest-trio to track this, though I'm not sure how urgently we should worry about it: python-trio/pytest-trio#74 |
I don't think there's are any todo items for us here right now? @lordi Please re-open if you think of any (and let us know how it goes!) |
Right, thanks for the pointers! I think porting the tests to non-unittest will be my go-to way. |
I have a whole test suite written with asynctest that I'd like to port to trio.
Is there a adapter class I could use? Simply decorating a unittest method with @trio_test did not work.
The text was updated successfully, but these errors were encountered: