-
Notifications
You must be signed in to change notification settings - Fork 24
Using pytest-asyncio fixtures with pytest-twisted functions #188
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
Comments
As a hack I was able to make |
It seems like a thing that should be doable, though I'll note that I don't work with twisted anymore so it's kind of random whether this grabs my attention vs. other things I might work on. Could you say some more about the situation that makes this needed? Mostly just fill in some of the details as I think this through (maybe). Here is where we both decide if we are going to handle a fixture ( pytest-twisted/src/pytest_twisted/__init__.py Lines 290 to 306 in ed7f494
Off the top of my head, I think we would need to make that more aware of what test is being run and whether it is a pytest-twisted handled test. I'm not sure if there would be more conditions needed around that like perhaps an option to enable this feature. Maybe. There would also need to be functionality akin to pytest-twisted/src/pytest_twisted/__init__.py Lines 333 to 348 in ed7f494
Or, who knows, maybe there's some core issue I haven't thought of yet that makes it all impossible. |
I have a Scrapy spider (and I need to run it in the test function which requires Twisted and its reactor) and a test website written using aiohttp that I want to scrape with that spider (and I want to run it in-process so I need a fixture that uses the
Oh so you want to run the non-Twisted asyncio parts (so to say) using the pytest-twisted machinery? That makes sense (though I don't know if it's possible). OTOH e.g. |
Thanks for filling that in. Yeah, twisted stuff can call asyncio stuff when using the asyncio reactor, just need to use the proper incantation. But also yes, it's got some obvious potential issues. I guess https://github.com/twisted/twisted/pull/1538/files is actually where I would have been doing that crossover stuff. I don't think the sniffio twisted support ever got done. Not saying this is the solution, but fyi that afaik you should be able to isolate twisted and asyncio loops in separate threads. Processes shouldn't be required. |
For the record, while moving stuff to a separate thread was harder than I thought, I was able to omit |
I'm glad you got to a working state. Let's certainly leave this issue open in case other folks have thoughts or time for it. |
I've initially asked this at https://stackoverflow.com/questions/79451761/using-pytest-twisted-functions-with-pytest-asyncio-fixtures but I now suspect that this is just not possible with the current pytest-twisted code, but maybe it is? If it isn't possible now, can pytest-twisted be improved to support this?
Basically I want to use
@pytest_asyncio.fixture
fixtures in test functions that use Twisted with--reactor=asyncio
. It seems that for this to work correctly all pieces need to use the same asyncio event loop? And there is no way to either create a loop and pass it to bothpytest-twisted
andpytest-asyncio
or extract the loop used by one of these and pass it to another one? If this line of reasoning is correct (and if I understand how do the pieces work), can it be made possible to modify one or both plugins to be able to share the loop/use the installed one?I also wonder if there are any workarounds in the mean time.
Thank you.
The text was updated successfully, but these errors were encountered: