-
Notifications
You must be signed in to change notification settings - Fork 149
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
RuntimeError: Cannot run the event loop while another loop is running #359
Comments
Thank you for the report and the example. Unfortunately, I will not have time to look into this for the next two weeks. If nobody else is going to pick this up, it'll have to wait until then. |
Hi, I also encountered a similar problem. import pytest
import asyncio
# using nest_asyncio mitigates the problem
#import nest_asyncio
#nest_asyncio.apply()
async def runner():
pytest.main(['-k', 'test_asdf', 'test_file.py'])
loop = asyncio.get_event_loop()
loop.run_until_complete(runner())
# does not raise an exception
# pytest.main(['-k', 'test_asdf', 'test_file.py'])
import pytest
@pytest.mark.asyncio
async def test_asdf():
assert True Executing the runner yields the same stacktrace:
The problem is that there is an existing event loop that is already running and I suspect that is happening on @SilenceHe 's imported code This can be mitigated by using nest_asyncio. I tried other solutions but unfortunately it seems like using nest_asyncio is the best option. |
one issue here is that you're expecting an async_api.Page, but pytest-playright uses the sync_api.Page https://github.com/microsoft/playwright-pytest/blob/456f8286f09f132d2e21f6bf71f27465e71ba17a/pytest_playwright/pytest_playwright.py#L22 import pytest
from playwright.async_api import Page
@pytest.mark.asyncio
async def test_bing(page: Page):
await page.goto("http://www.bing.com/") |
@graingert Thanks for jumping in! As mentioned playwright-pytest only supports the synchronous Playwright API at the moment (see microsoft/playwright-pytest#74). @SilenceHe This comment in particular state that only |
I didn't know about nest_asyncio. The project seems to solve the same problem as https://github.com/aio-libs/aioloop-proxy for which a draft PR exists (#312). @PeterStolz Your error message is similar to that of the OP. I see your problem as a different one, though, because it has nothing to do with playwright-pytest. Do you mind opening a separate issue for your? It would be very helpful if you could explain your use case a bit more. CC @asvetlov It seems that nest_asyncio and aioloop-proxy do pretty much the same. |
Closing this issue as this doesn't seem to be a pytest-asyncio bug. Feel free to reopen, especially if there is anything we can do to improve support for playwright-pytest. |
When trying to do UI automtion with pytest-asyncio and pytest-playwright, I got exception like: RuntimeError: Cannot run the event loop while another loop is running
Code structure:
ui2/conftest.py
ui2/test_bing.py
env:
Detail exception as below:
The text was updated successfully, but these errors were encountered: