Pytest plugin that captures HTML, screenshots, and console logs on Playwright test failures
Project description
Capture debugging artifacts on Playwright test failures
When your Playwright tests fail, you need to see what went wrong. This pytest plugin automatically captures HTML, screenshots, console logs, and failure summaries the moment a test fails.
I built this because debugging failed tests without artifacts is painful. You're left guessing what the page looked like, what JavaScript errors occurred, or what the actual DOM content was. This plugin captures all of that automatically.
Installation
uv add pytest-playwright-artifacts
Usage
The plugin activates automatically once installed. No configuration needed.
Basic Test
def test_my_page(page):
page.goto("https://example.com")
assert page.title() == "Example"
When this test fails, you'll find artifacts in test-results/<test-name>/:
failure.html- Rendered DOM content at the moment of failurescreenshot.png- Full-page screenshotfailure.txt- Failure summary with tracebackconsole_logs.log- All captured console messages
Fail tests on console errors
from pytest_playwright_artifacts import assert_no_console_errors
def test_no_console_errors(page, request):
page.goto("https://example.com")
assert_no_console_errors(request)
This fails the test if any console.error() messages were logged during the test.
Features
- Automatic artifact capture on test failure: HTML, screenshots, failure summary, and console logs
- Console log monitoring for all browser console messages during tests
- Regex-based filtering to ignore noisy console messages
- Helper assertion
assert_no_console_errors()to fail tests on console errors - Per-test artifact directories for clean organization
Configuration
Filter noisy console messages
Use regex patterns to ignore known noisy messages:
pyproject.toml:
[tool.pytest.ini_options]
playwright_console_ignore = [
"Invalid Sentry Dsn:.*",
"Radar SDK: initialized.*",
"\\[Meta Pixel\\].*",
]
pytest.ini:
[pytest]
playwright_console_ignore =
Invalid Sentry Dsn:.*
Radar SDK: initialized.*
\\[Meta Pixel\\].*
Patterns match against both the raw console text and the formatted log line.
Change artifact output directory
pytest --output=my-artifacts
How it works
The plugin uses pytest hooks and fixtures to capture artifacts:
- An autouse fixture attaches a console listener to every Playwright page
- Console logs are stored in memory at
request.config._playwright_console_logs[nodeid] - The
pytest_runtest_makereporthook detects test failures - On failure, the plugin captures page content, takes a screenshot, and writes all artifacts
- Console logs are cleaned up from memory after test completion
Disabling features
Disable console logging:
# In pytest_playwright_artifacts/plugin.py, change:
@pytest.fixture(autouse=False)
def playwright_console_logging(...):
Disable failure artifacts:
Comment out the pytest_runtest_makereport hook in plugin.py.
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_playwright_artifacts-0.1.0.tar.gz.
File metadata
- Download URL: pytest_playwright_artifacts-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8eb437598dd054b4604b18fd0f88cfe20d607a4c8db2da9dd994c39d120d3d1
|
|
| MD5 |
49351277f3bdd73f6d24fb1c0861321e
|
|
| BLAKE2b-256 |
c8f14e67bfa8c30b365847cc2f91d8ed1b1dbf9ea31b761dc27cef357a5afcfc
|
File details
Details for the file pytest_playwright_artifacts-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_playwright_artifacts-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
750392c2c76ee14f74cf8f39e9060da620cf6db1f24d137b061d410d254215c3
|
|
| MD5 |
46d3267bbd2502d62175ac014b1d6cd6
|
|
| BLAKE2b-256 |
7ae1631dd27ff80c3ba4a8a0784a4cc40ea21c034a6dfb58e361dfe97c413e5d
|