diff --git a/Justfile b/Justfile index 657881be..5fcd9afd 100644 --- a/Justfile +++ b/Justfile @@ -11,6 +11,22 @@ export DATASETTE_SECRET := "not_a_secret" @test *options: init uv run pytest -n auto {{options}} +# Install Playwright browser support, Chromium by default +@playwright-install browser="chromium": + uv run --group playwright playwright install {{browser}} + +# Install all Playwright browsers used by the test suite +@playwright-install-all: + uv run --group playwright playwright install chromium firefox webkit + +# Run Playwright tests, Chromium by default +@playwright browser="chromium" *options: + uv run --group playwright pytest tests/test_playwright.py --playwright --browser {{browser}} {{options}} + +# Run Playwright tests against all supported browsers +@playwright-all *options: + uv run --group playwright pytest tests/test_playwright.py --playwright --browser chromium --browser firefox --browser webkit {{options}} + @codespell: uv run codespell README.md --ignore-words docs/codespell-ignore-words.txt uv run codespell docs/*.rst --ignore-words docs/codespell-ignore-words.txt diff --git a/docs/contributing.rst b/docs/contributing.rst index d4fcb19d..0d365f3a 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -71,24 +71,42 @@ These tests are skipped by default, so you can run the main test suite with .. _Playwright: https://playwright.dev/python/ -The Playwright tests use a separate dependency group. To run them, first install -the browser engine you want to test against, for example Chromium:: +The Playwright tests use a separate dependency group. The easiest way to run +them is using ``just``. First install the browser engine you want to test +against. Chromium is used by default:: + + just playwright-install + +Then run the Playwright test module:: + + just playwright + +You can also run the same tests against Firefox or WebKit by installing that +browser engine and passing it to ``just playwright``:: + + just playwright-install firefox + just playwright firefox + + just playwright-install webkit + just playwright webkit + +To install every supported browser engine and run the tests against all of +them, use:: + + just playwright-install-all + just playwright-all + +You can pass extra ``pytest`` options after the browser name:: + + just playwright chromium -k permissions + just playwright-all -x + +If you are not using ``just``, the equivalent Chromium commands are:: uv run --group playwright playwright install chromium -Then run the Playwright test module with the explicit ``--playwright`` flag:: - uv run --group playwright pytest tests/test_playwright.py --playwright --browser chromium -You can also run the same tests against Firefox or WebKit by installing that -browser engine and passing it to ``--browser``:: - - uv run --group playwright playwright install firefox - uv run --group playwright pytest tests/test_playwright.py --playwright --browser firefox - - uv run --group playwright playwright install webkit - uv run --group playwright pytest tests/test_playwright.py --playwright --browser webkit - .. _contributing_using_fixtures: Using fixtures diff --git a/tests/conftest.py b/tests/conftest.py index 04b6f8be..55110a42 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -93,7 +93,17 @@ def pytest_report_header(config): conn = sqlite3.connect(":memory:") version = conn.execute("select sqlite_version()").fetchone()[0] conn.close() - return "SQLite: {}".format(version) + headers = ["SQLite: {}".format(version)] + if config.getoption("--playwright"): + try: + browsers = config.getoption("--browser") + except ValueError: + browsers = None + if isinstance(browsers, str): + browsers = [browsers] + if browsers: + headers.append("Playwright browsers: {}".format(", ".join(browsers))) + return headers def pytest_addoption(parser):