Playwright-Pytest Error: It looks like you are using Playwright Sync API inside the asyncio loop

I am able to run testcases individually using pytest and class,function fixture:

pytest test_fixtures_class.py

But when I am trying to run all classes testcases using:

pytest

I am getting following error

test_fixtures_class.py::Test_titleclass::test_portfolio – playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.

pytest test_fixtures_class.py

import pytest
from playwright.sync_api import sync_playwright

@pytest.fixture(scope='class')
def browser(request):
    with sync_playwright() as p:
        browser=p.chromium.launch(headless=False)
        # Attach the browser instance to the test class
        request.cls.browser=browser 
        yield browser
        browser.close()

# Define a fixture with function-level scope      
@pytest.fixture(scope='function')
def page(browser):
    page=browser.new_page()
    yield page
    page.close()
    
    
# Use the 'browser' fixture for the following test class
@pytest.mark.usefixtures('browser')
class Test_titleclass:
    def test_google(self,page):
        page.goto('https://google.com')
        assert 'Google' == page.title()
        
    def test_portfolio(self,page):
        page.goto('https://github-portfolio-pst99.vercel.app/')
        assert 'My Portfolio' == page.title()
        
    

Terminal Error

PS C:UsersPrashantDesktopplaywright-pythonpytest> pytest
======================================================== test session starts ========================================================
platform win32 -- Python 3.12.2, pytest-8.2.2, pluggy-1.5.0
baseurl: https://www.saucedemo.com/
rootdir: C:UsersPrashantDesktopplaywright-pythonpytest
configfile: pytest.ini
plugins: asyncio-0.23.7, base-url-2.1.0, html-4.1.1, metadata-3.1.1, playwright-0.5.0
asyncio: mode=Mode.STRICT
collected 9 items

test_OrangeHRM.py .                                                                                                            [ 11%]
test_demo.py ..                                                                                                                [ 33%]
test_fixtures_class.py EE                                                                                                      [ 55%]
test_fixtures_module.py EE                                                                                                     [ 77%]
test_parameter.py EE                                                                                                           [100%]

============================================================== ERRORS =============================================================== 
___________________________________________ ERROR at setup of Test_titleclass.test_google ___________________________________________ 

request = <SubRequest 'browser' for <Function test_google>>

    @pytest.fixture(scope='class')
    def browser(request):
>       with sync_playwright() as p:

test_fixtures_class.py:6:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <playwright.sync_api._context_manager.PlaywrightContextManager object at 0x000001BF7E4FFB30>

        def __enter__(self) -> SyncPlaywright:
            try:
                self._loop = asyncio.get_running_loop()
            except RuntimeError:
                self._loop = asyncio.new_event_loop()
                self._own_loop = True
            if self._loop.is_running():
>               raise Error(
                    """It looks like you are using Playwright Sync API inside the asyncio loop.
    Please use the Async API instead."""
                )
E               playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
E               Please use the Async API instead.

......AppDataLocalProgramsPythonPython312Libsite-packagesplaywrightsync_api_context_manager.py:47: Error
_________________________________________ ERROR at setup of Test_titleclass.test_portfolio __________________________________________ 

request = <SubRequest 'browser' for <Function test_google>>

    @pytest.fixture(scope='class')
    def browser(request):
>       with sync_playwright() as p:

test_fixtures_class.py:6:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <playwright.sync_api._context_manager.PlaywrightContextManager object at 0x000001BF7E4FFB30>

        def __enter__(self) -> SyncPlaywright:
            try:
                self._loop = asyncio.get_running_loop()
            except RuntimeError:
                self._loop = asyncio.new_event_loop()
                self._own_loop = True
            if self._loop.is_running():
>               raise Error(
                    """It looks like you are using Playwright Sync API inside the asyncio loop.
    Please use the Async API instead."""
                )
E               playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
E               Please use the Async API instead.

......AppDataLocalProgramsPythonPython312Libsite-packagesplaywrightsync_api_context_manager.py:47: Error
___________________________________________________ ERROR at setup of test_google ___________________________________________________ 

    @pytest.fixture(scope="module")
    def browser():
>       with sync_playwright() as p:

test_fixtures_module.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <playwright.sync_api._context_manager.PlaywrightContextManager object at 0x000001BF7E599C70>

        def __enter__(self) -> SyncPlaywright:
            try:
                self._loop = asyncio.get_running_loop()
            except RuntimeError:
                self._loop = asyncio.new_event_loop()
                self._own_loop = True
            if self._loop.is_running():
>               raise Error(
                    """It looks like you are using Playwright Sync API inside the asyncio loop.
    Please use the Async API instead."""
                )
E               playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
E               Please use the Async API instead.

......AppDataLocalProgramsPythonPython312Libsite-packagesplaywrightsync_api_context_manager.py:47: Error
_________________________________________________ ERROR at setup of test_portfolio __________________________________________________ 

    @pytest.fixture(scope="module")
    def browser():
>       with sync_playwright() as p:

test_fixtures_module.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <playwright.sync_api._context_manager.PlaywrightContextManager object at 0x000001BF7E599C70>

        def __enter__(self) -> SyncPlaywright:
            try:
                self._loop = asyncio.get_running_loop()
            except RuntimeError:
                self._loop = asyncio.new_event_loop()
                self._own_loop = True
            if self._loop.is_running():
>               raise Error(
                    """It looks like you are using Playwright Sync API inside the asyncio loop.
    Please use the Async API instead."""
                )
E               playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
E               Please use the Async API instead.

......AppDataLocalProgramsPythonPython312Libsite-packagesplaywrightsync_api_context_manager.py:47: Error
___________________________________________ ERROR at setup of test_parameter[admin-admin] ___________________________________________ 

    @pytest.fixture(scope="module")
    def browser():
>       with sync_playwright() as p:

test_parameter.py:6:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <playwright.sync_api._context_manager.PlaywrightContextManager object at 0x000001BF7E599520>

        def __enter__(self) -> SyncPlaywright:
            try:
                self._loop = asyncio.get_running_loop()
            except RuntimeError:
                self._loop = asyncio.new_event_loop()
                self._own_loop = True
            if self._loop.is_running():
>               raise Error(
                    """It looks like you are using Playwright Sync API inside the asyncio loop.
    Please use the Async API instead."""
                )
E               playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
E               Please use the Async API instead.

......AppDataLocalProgramsPythonPython312Libsite-packagesplaywrightsync_api_context_manager.py:47: Error
____________________________________________ ERROR at setup of test_parameter[test-test] ____________________________________________ 

    @pytest.fixture(scope="module")
    def browser():
>       with sync_playwright() as p:

test_parameter.py:6:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <playwright.sync_api._context_manager.PlaywrightContextManager object at 0x000001BF7E599520>

        def __enter__(self) -> SyncPlaywright:
            try:
                self._loop = asyncio.get_running_loop()
            except RuntimeError:
                self._loop = asyncio.new_event_loop()
                self._own_loop = True
            if self._loop.is_running():
>               raise Error(
                    """It looks like you are using Playwright Sync API inside the asyncio loop.
    Please use the Async API instead."""
                )
E               playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
E               Please use the Async API instead.

......AppDataLocalProgramsPythonPython312Libsite-packagesplaywrightsync_api_context_manager.py:47: Error
====================================================== short test summary info ====================================================== 
ERROR test_fixtures_class.py::Test_titleclass::test_google - playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
ERROR test_fixtures_class.py::Test_titleclass::test_portfolio - playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
ERROR test_fixtures_module.py::test_google - playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
ERROR test_fixtures_module.py::test_portfolio - playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
ERROR test_parameter.py::test_parameter[admin-admin] - playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
ERROR test_parameter.py::test_parameter[test-test] - playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
=================================================== 3 passed, 6 errors in 11.83s ==================================================== ```


Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật