pytest-image-diff
Installation
pip install pytest-image-diff
or from git
pip install -e git+https://githib.com/Apkawa/pytest-image-diff.git@master#egg=pytest-image-diff
Python>=3.6
Usage
from typing import Union
from PIL import Image
def test_compare(image_diff):
image: Image or str or bytes = Image.new()
image2: Image or str or bytes = '/path/to/image.jpeg'
image_diff(image, image2)
def test_regression(image_regression):
image: Union[Image, str, bytes] = Image.new()
image_regression(image, threshold=0.5)
Also use with assert
import pytest
from typing import Union
from PIL import Image
@pytest.fixture(scope="session")
def image_diff_throw_exception() -> bool:
"""
Set default throw exception. By default - True
"""
return False
def test_compare(image_diff):
image: Image or str or bytes = Image.new()
image2: Image or str or bytes = '/path/to/image.jpeg'
assert image_diff(image, image2)
assert image_diff(image, image2, threshold=0.5)
# Also can check threshold in compare, ie
assert image_diff(image, image2) < 0.5
# For different checks in one test
assert image_diff(image, image2, threshold=0.5, suffix="one")
# Or without fixture image_diff_throw_exception
assert image_diff(image, image2, threshold=0.5, throw_exception=False)
def test_regression(image_regression):
image: Union[Image, str, bytes] = Image.new()
assert image_regression(image, threshold=0.5)
# Also can check threshold in compare, ie
assert image_regression(image) < 0.5
# For different checks in one test
assert image_regression(image, threshold=0.5, suffix="foo")
# Or without fixture image_diff_throw_exception
assert image_regression(image, threshold=0.5, throw_exception=False)
First run creates reference images
pytest-splinter
Fixture screenshot_regression enabled if pytest-splinter installed
import pytest
@pytest.fixture
def admin_browser(request, browser_instance_getter):
"""Admin browser fixture."""
# browser_instance_getter function receives parent fixture -- our admin_browser
return browser_instance_getter(request, admin_browser)
def test_2_browsers(browser, admin_browser, screenshot_regression):
"""Test using 2 browsers at the same time."""
browser.visit('http://google.com')
admin_browser.visit('http://admin.example.com')
screenshot_regression(suffix="browser")
screenshot_regression(admin_browser, suffix="admin browser")
def test_pytest_splinter(browser, screenshot_regression):
# Recommend fix window size for avoid regression
browser.driver.set_window_size(1280, 1024)
browser.visit('http://google.com')
screenshot_regression(suffix="main")
# ... some interaction
browser.click()
screenshot_regression(suffix="success")
# you can use xpath expression for part of page
screenshot_regression(xpath="//h1")
Metadata
Release files for pytest-image-diff 0.0.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_image_diff-0.0.14.tar.gz | 11.6 kB | Without provenance | Details for pytest_image_diff-0.0.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_image_diff-0.0.14-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for pytest_image_diff-0.0.14-py2.py3-none-any.whl |
Total release size: 22.5 kB
Release files / pytest_image_diff-0.0.14.tar.gz
| Download URL | pytest_image_diff-0.0.14.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2405dba60c8009c93a7cafc15976cc8f2b1b8f33ffe8126e35d72a6d22e19850
|
|
BLAKE2b-256 checksum How to use checksums |
be7564a17eb4b43d01437387e463a2c3083fe27d169174d9fade0cc52f18bfe1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Release files / pytest_image_diff-0.0.14-py2.py3-none-any.whl
| Download URL | pytest_image_diff-0.0.14-py2.py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
106642ab02c7be579aed7085f5ca670108ad43cfaff0980690383185a2fb5ad4
|
|
BLAKE2b-256 checksum How to use checksums |
407dbe27575980da987cc7af4d7e9f27f2bc141a8e002a7e6809e16e71c13a1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Security for pytest-image-diff 0.0.14
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.