Ошибка Playwright-Pytest: похоже, что вы используете API Sync Sync Playwright в цикле AsyncioPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Ошибка Playwright-Pytest: похоже, что вы используете API Sync Sync Playwright в цикле Asyncio

Сообщение Anonymous »

Я могу запустить тестовые шкафы индивидуально, используя Pytest и класс, функциональный прибор: pytest test_fixtures_class.py .
Но когда я пытаюсь запустить все тестовые шкалы классов, используя команду pytest , я получаю следующую ошибку:
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()

< /code>
Ошибка терминала < /p>
PS C:\Users\Desktop\playwright-python\pytest> 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:\Users\Desktop\playwright-python\pytest
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 =

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

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

self =

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.

..\..\..\AppData\Local\Programs\Python\Python312\Lib\site-packages\playwright\sync_api\_context_manager.py:47: Error
_________________________________________ ERROR at setup of Test_titleclass.test_portfolio __________________________________________

request =

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

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

self =

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.

..\..\..\AppData\Local\Programs\Python\Python312\Lib\site-packages\playwright\sync_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 =

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.

..\..\..\AppData\Local\Programs\Python\Python312\Lib\site-packages\playwright\sync_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 =

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.

..\..\..\AppData\Local\Programs\Python\Python312\Lib\site-packages\playwright\sync_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 =

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.

..\..\..\AppData\Local\Programs\Python\Python312\Lib\site-packages\playwright\sync_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 =

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.

..\..\..\AppData\Local\Programs\Python\Python312\Lib\site-packages\playwright\sync_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 ==================================================== ```



Подробнее здесь: https://stackoverflow.com/questions/786 ... api-inside
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»