[![PyPi](https://img.shields.io/pypi/v/pytest-image-diff.svg)](https://pypi.python.org/pypi/pytest-image-diff)
[![ci](https://github.com/Apkawa/pytest-image-diff/actions/workflows/ci.yml/badge.svg)](https://github.com/Apkawa/pytest-image-diff/actions/workflows/ci.yml)
[![Documentation Status](https://readthedocs.org/projects/pytest-image-diff/badge/?version=latest)](https://pytest-image-diff.readthedocs.io/en/latest/?badge=latest)
[![Codecov](https://codecov.io/gh/Apkawa/pytest-image-diff/branch/master/graph/badge.svg)](https://codecov.io/gh/Apkawa/pytest-image-diff)
[![PyPi Python versions](https://img.shields.io/pypi/pyversions/pytest-image-diff.svg)](https://pypi.python.org/pypi/pytest-image-diff)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
# pytest-image-diff
# Installation
```bash
pip install pytest-image-diff
```
or from git
```bash
pip install -e git+https://githib.com/Apkawa/pytest-image-diff.git@master#egg=pytest-image-diff
```
Python>=3.6
# Usage
```python
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
```python
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
```python3
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")
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Apkawa/pytest-image-diff",
"name": "pytest-image-diff",
"maintainer": null,
"docs_url": null,
"requires_python": "<4,>=3.6",
"maintainer_email": null,
"keywords": "pytest",
"author": "Apkawa",
"author_email": "apkawa@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/be/75/64a17eb4b43d01437387e463a2c3083fe27d169174d9fade0cc52f18bfe1/pytest_image_diff-0.0.14.tar.gz",
"platform": null,
"description": "[![PyPi](https://img.shields.io/pypi/v/pytest-image-diff.svg)](https://pypi.python.org/pypi/pytest-image-diff)\n[![ci](https://github.com/Apkawa/pytest-image-diff/actions/workflows/ci.yml/badge.svg)](https://github.com/Apkawa/pytest-image-diff/actions/workflows/ci.yml)\n[![Documentation Status](https://readthedocs.org/projects/pytest-image-diff/badge/?version=latest)](https://pytest-image-diff.readthedocs.io/en/latest/?badge=latest)\n[![Codecov](https://codecov.io/gh/Apkawa/pytest-image-diff/branch/master/graph/badge.svg)](https://codecov.io/gh/Apkawa/pytest-image-diff)\n[![PyPi Python versions](https://img.shields.io/pypi/pyversions/pytest-image-diff.svg)](https://pypi.python.org/pypi/pytest-image-diff)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\n# pytest-image-diff\n\n# Installation\n\n```bash\npip install pytest-image-diff\n```\n\nor from git\n\n```bash\npip install -e git+https://githib.com/Apkawa/pytest-image-diff.git@master#egg=pytest-image-diff\n```\n\nPython>=3.6\n\n\n# Usage\n\n```python\nfrom typing import Union\nfrom PIL import Image\n\n\ndef test_compare(image_diff):\n image: Image or str or bytes = Image.new()\n image2: Image or str or bytes = '/path/to/image.jpeg'\n image_diff(image, image2)\n\n\ndef test_regression(image_regression):\n image: Union[Image, str, bytes] = Image.new()\n image_regression(image, threshold=0.5)\n```\n\nAlso use with assert\n\n```python\nimport pytest\n\nfrom typing import Union\nfrom PIL import Image\n\n@pytest.fixture(scope=\"session\")\ndef image_diff_throw_exception() -> bool:\n \"\"\"\n Set default throw exception. By default - True\n \"\"\"\n return False\n\ndef test_compare(image_diff):\n image: Image or str or bytes = Image.new()\n image2: Image or str or bytes = '/path/to/image.jpeg'\n assert image_diff(image, image2)\n assert image_diff(image, image2, threshold=0.5)\n # Also can check threshold in compare, ie\n assert image_diff(image, image2) < 0.5\n # For different checks in one test\n assert image_diff(image, image2, threshold=0.5, suffix=\"one\")\n # Or without fixture image_diff_throw_exception\n assert image_diff(image, image2, threshold=0.5, throw_exception=False)\n\n\ndef test_regression(image_regression):\n image: Union[Image, str, bytes] = Image.new()\n assert image_regression(image, threshold=0.5)\n # Also can check threshold in compare, ie\n assert image_regression(image) < 0.5\n # For different checks in one test\n assert image_regression(image, threshold=0.5, suffix=\"foo\")\n # Or without fixture image_diff_throw_exception\n assert image_regression(image, threshold=0.5, throw_exception=False)\n```\n\nFirst run creates reference images\n\n## pytest-splinter\n\nFixture `screenshot_regression` enabled if pytest-splinter installed\n\n```python3\nimport pytest\n\n@pytest.fixture\ndef admin_browser(request, browser_instance_getter):\n \"\"\"Admin browser fixture.\"\"\"\n # browser_instance_getter function receives parent fixture -- our admin_browser\n return browser_instance_getter(request, admin_browser)\n\ndef test_2_browsers(browser, admin_browser, screenshot_regression):\n \"\"\"Test using 2 browsers at the same time.\"\"\"\n browser.visit('http://google.com')\n admin_browser.visit('http://admin.example.com')\n\n screenshot_regression(suffix=\"browser\")\n screenshot_regression(admin_browser, suffix=\"admin browser\")\n\ndef test_pytest_splinter(browser, screenshot_regression):\n # Recommend fix window size for avoid regression\n browser.driver.set_window_size(1280, 1024)\n\n browser.visit('http://google.com')\n\n screenshot_regression(suffix=\"main\")\n # ... some interaction\n browser.click()\n screenshot_regression(suffix=\"success\")\n # you can use xpath expression for part of page\n screenshot_regression(xpath=\"//h1\")\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": null,
"version": "0.0.14",
"project_urls": {
"Homepage": "https://github.com/Apkawa/pytest-image-diff"
},
"split_keywords": [
"pytest"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "407dbe27575980da987cc7af4d7e9f27f2bc141a8e002a7e6809e16e71c13a1a",
"md5": "ec0dda737cdeed33995ab011e834cb3b",
"sha256": "106642ab02c7be579aed7085f5ca670108ad43cfaff0980690383185a2fb5ad4"
},
"downloads": -1,
"filename": "pytest_image_diff-0.0.14-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "ec0dda737cdeed33995ab011e834cb3b",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": "<4,>=3.6",
"size": 10859,
"upload_time": "2024-12-31T09:08:23",
"upload_time_iso_8601": "2024-12-31T09:08:23.321409Z",
"url": "https://files.pythonhosted.org/packages/40/7d/be27575980da987cc7af4d7e9f27f2bc141a8e002a7e6809e16e71c13a1a/pytest_image_diff-0.0.14-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "be7564a17eb4b43d01437387e463a2c3083fe27d169174d9fade0cc52f18bfe1",
"md5": "9675c3c48bb87d5024b5a93453297f1e",
"sha256": "2405dba60c8009c93a7cafc15976cc8f2b1b8f33ffe8126e35d72a6d22e19850"
},
"downloads": -1,
"filename": "pytest_image_diff-0.0.14.tar.gz",
"has_sig": false,
"md5_digest": "9675c3c48bb87d5024b5a93453297f1e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.6",
"size": 11596,
"upload_time": "2024-12-31T09:08:24",
"upload_time_iso_8601": "2024-12-31T09:08:24.458444Z",
"url": "https://files.pythonhosted.org/packages/be/75/64a17eb4b43d01437387e463a2c3083fe27d169174d9fade0cc52f18bfe1/pytest_image_diff-0.0.14.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-31 09:08:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Apkawa",
"github_project": "pytest-image-diff",
"travis_ci": true,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "pytest-image-diff"
}