Skip to content

RuntimeError: Cannot run the event loop while another loop is running #359

Closed
@baiyyee

Description

@baiyyee

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

ui2/conftest.py

import pytest
import asyncio


@pytest.fixture(scope="session")
def event_loop():
    """重写event_loop"""

    loop = asyncio.get_event_loop()
    yield loop
    loop.close()

ui2/test_bing.py

import pytest

from playwright.async_api import Page


@pytest.mark.asyncio
async def test_bing(page: Page):
    await page.goto("http://www.bing.com")

env:

pytest==7.1.2
pytest-asyncio==0.18.3
pytest-playwright==0.3.0

Detail exception as below:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions