pytest-playwright-asyncio

raw JSON →
0.7.2 verified Mon Apr 27 auth: no python

A pytest plugin providing async fixtures for Playwright (via asyncio), enabling async/await browser automation in tests. Current version 0.7.2, requires Python >=3.10. Released as needed; follows pytest-playwright patterns.

pip install pytest-playwright-asyncio
error RuntimeError: Event loop is closed
cause pytest-asyncio mode conflict: using 'auto' or 'strict' mode incorrectly.
fix
Set in pytest.ini: [pytest] asyncio_mode = auto or use @pytest.mark.asyncio explicitly.
error ModuleNotFoundError: No module named 'pytest_playwright_asyncio'
cause pytest cannot find the plugin because it's not installed or not imported in conftest.
fix
Install the package and ensure conftest.py has 'pytest_plugins = ["pytest_playwright_asyncio"]'.
error playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside an asyncio test
cause Using sync Playwright methods (e.g., page.goto() without await) in an async test.
fix
Ensure all Playwright calls are awaited: await page.goto('...')
breaking Version 0.7.0 dropped support for Python 3.8/3.9 and changed the default fixture scope from function to session. Tests relying on function-level isolation may fail.
fix If you need function-scoped fixtures, explicitly set scope='function' in conftest.py.
gotcha The 'page' fixture returns a new page in a new context per test by default. Do not reuse pages across tests as they are isolated.
fix Use the 'context' fixture to share state between pages within a test.
deprecated The 'browser' fixture is deprecated in favor of 'browser_type' and 'launch_browser' for clarity.
fix Use 'browser_type.launch()' instead of relying on the 'browser' fixture.
playwright install

Basic async test using the page fixture. Ensure you have a conftest.py with the plugin import or set pytest_plugins.

import pytest
from playwright.async_api import Page

pytest_plugins = ['pytest_playwright_asyncio']

async def test_example(page: Page):
    await page.goto('https://example.com')
    assert await page.title() == 'Example Domain'