Skip to main content

Pytest Screenshot on Failure

Saves a screenshot when a test case from a pytest execution fails.

Requirements

This plugin requires that you have an instance of your selenium WebDriver being yielded by a @pytext.fixture, in your conftest.py file.

This is not just a good practice, but it also helps pytest-screenshot-on-failure to identify your WebDriver instance for the moment it needs to capture a screenshot.

# conftest.py
from selenium import webdriver
from selenium.webdriver import Chrome

# WebDriver fixture example
@pytest.fixture(scope='session', autouse=True)
def web_driver():
    options = webdriver.ChromeOptions()
    driver = Chrome(options=options)
    
    yield driver
    
    driver.quit()

How to use

You can enable this plugin by using the --save_screenshots flag when running your tests.

Example:

python3 -m pytest /tests --save_screenshots

The screenshots will be saved by default into the "screenshots" folder. You can change this folder name by using the flag --screenshots_dir=<custom_dir_name>.

Example:

python3 -m pytest /tests --save_screenshots --screenshots_dir=images

Screenshots folder structure

  • The screenshots from the latest execution will be saved directly on the screenshots root folder, with the date/time of the execution.
  • Give your test file a class name, and the screenshots will be organized by test suite.
  • Whenever you star a new execution, older images will be stored in the history folder.

img.png

Test coverage

The current test coverage rate is 97%! It's only missing coverage on the pytest_runtest_makereport hook. I couldn't find a way of covering methods that yields a Generator, yet.

---------- coverage: platform linux, python 3.10.6-final-0 -----------
Name                                  Stmts   Miss  Cover   Missing
-------------------------------------------------------------------
src/__init__.py                           0      0   100%
src/pytest_screenshot_on_failure.py      91      3    97%   80-82
-------------------------------------------------------------------
TOTAL                                    91      3    97%

Static Analysis & Lint

The repository has no offenses on autoflake, yapf, isort and strict mypy checks. Pending to add CI/CD actions to assert these checks automatically.

Metadata

Release files for pytest-screenshot-on-failure 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-screenshot-on-failure 1.0.0
File Size Uploaded Provenance
pytest_screenshot_on_failure-1.0.0.tar.gz 6.9 kB Without provenance Details

Release files / pytest_screenshot_on_failure-1.0.0.tar.gz

Download URL pytest_screenshot_on_failure-1.0.0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2d03a5253ebfd25ecb9bc1e865eb9959a07ddf194d77b411f812f1a0c775325d
BLAKE2b-256 checksum
How to use checksums
6b2d5698b7dd25fa9a79147575373a799aafcc208f0258995367d32804bf936d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Security for pytest-screenshot-on-failure 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page