No project description provided
Project description
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")
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file pytest-image-diff-0.0.11.tar.gz
.
File metadata
- Download URL: pytest-image-diff-0.0.11.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50443ee1ad3cb5fa2d0b6cfc2d21a70eff8666a4d447e1f55e3e73f7b94413d9 |
|
MD5 | 6982f07c885ddc39a4ae8a682826dcb8 |
|
BLAKE2b-256 | 733b48c23e6cbb541ae9cf23cbafa33937353d00254b990b403f08be0617f914 |
File details
Details for the file pytest_image_diff-0.0.11-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_image_diff-0.0.11-py2.py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 370d3164cae1f834ff6fd9f8da2fefb96a8e34542a14d6988b8f73a9c1b2afb5 |
|
MD5 | 5848b04a63473a80cd1d8f70e360f05d |
|
BLAKE2b-256 | 93866161925c1d1562e5ae6d89bc86e00da05d499b70ab7350f00084f9f78d62 |