pytest-pyodide
raw JSON → 0.59.1 verified Mon Apr 27 auth: no python
A pytest plugin for testing applications that use Pyodide (Python in the browser). Current version 0.59.1, requires Python >=3.11. Active development with frequent releases.
pip install pytest-pyodide Common errors
error ModuleNotFoundError: No module named 'pytest_pyodide' ↓
cause pytest-pyodide not installed or installed in wrong environment.
fix
Ensure you are in the correct Python environment and run: pip install pytest-pyodide
error Fixture 'selenium' not found ↓
cause Selenium driver is not installed or the fixture has been renamed.
fix
Install selenium (pip install selenium) or use the Playwright driver: pip install playwright && playwright install
error ValueError: Package 'pandas' is not loaded. Did you include it in the decorator? ↓
cause Third-party packages must be explicitly listed in the run_in_pyodide decorator's packages argument.
fix
Change decorator to @run_in_pyodide(packages=['pandas'])
Warnings
breaking Classic web worker support dropped in 0.59.0. Tests must target modern browsers (Chrome/Firefox) via Selenium or Playwright. ↓
fix Use selenium fixture or switch to Playwright driver.
deprecated The 'selenium' fixture is deprecated in favor of browser-agnostic fixtures. Use 'webdriver' or 'playwright_browser' instead. ↓
fix Replace 'selenium' with 'webdriver' or configure Playwright.
gotcha Packages must be listed explicitly in @run_in_pyodide or added via conftest.py's pyodide_packages hook. Standard library modules like json, math are always available. ↓
fix Add required packages in the decorator: @run_in_pyodide(packages=['numpy', 'pandas'])
gotcha Tests run in a separate browser process; global state is not shared between tests. Each test receives a fresh Pyodide environment. ↓
fix Use fixtures to set up shared state explicitly.
Imports
- run_in_pyodide wrong
from pytest_pyodide.decorator import run_in_pyodidecorrectfrom pytest_pyodide import run_in_pyodide
Quickstart
import pytest
from pytest_pyodide import run_in_pyodide
@run_in_pyodide(packages=['numpy'])
def test_numpy_in_browser(selenium):
import numpy as np
assert np.array([1,2,3]).sum() == 6