pytest-image-diff


Namepytest-image-diff JSON
Version 0.0.10 PyPI version JSON
download
home_pagehttps://github.com/Apkawa/pytest-image-diff
Summary
upload_time2023-01-29 15:28:31
maintainer
docs_urlNone
authorApkawa
requires_python>=3.6, <4
licenseMIT
keywords pytest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            [![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": "",
    "docs_url": null,
    "requires_python": ">=3.6, <4",
    "maintainer_email": "",
    "keywords": "pytest",
    "author": "Apkawa",
    "author_email": "apkawa@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/35/c7/db5b4b06f0115483d05fa91aa23259a3ce880865e1f1203ce5a8b2f43fa0/pytest-image-diff-0.0.10.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": "",
    "version": "0.0.10",
    "split_keywords": [
        "pytest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "335382f6110b98c11baf33e8fdb729c7588118bbb50f0ec6d0e01d359cdc0132",
                "md5": "3d8056da9cf86e31eaf7f1ded5b6dd5f",
                "sha256": "89e5ff37065b29252035f27720e6dc3828d5cc3dde1d16904fa494e115cb206f"
            },
            "downloads": -1,
            "filename": "pytest_image_diff-0.0.10-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3d8056da9cf86e31eaf7f1ded5b6dd5f",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.6, <4",
            "size": 10159,
            "upload_time": "2023-01-29T15:28:29",
            "upload_time_iso_8601": "2023-01-29T15:28:29.821285Z",
            "url": "https://files.pythonhosted.org/packages/33/53/82f6110b98c11baf33e8fdb729c7588118bbb50f0ec6d0e01d359cdc0132/pytest_image_diff-0.0.10-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "35c7db5b4b06f0115483d05fa91aa23259a3ce880865e1f1203ce5a8b2f43fa0",
                "md5": "2437e911d6b82a3ddab0c28d1c796796",
                "sha256": "c016c0bbce51c3514a19255bff2389039ed2881175444f87b1595cf8b83707d6"
            },
            "downloads": -1,
            "filename": "pytest-image-diff-0.0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "2437e911d6b82a3ddab0c28d1c796796",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6, <4",
            "size": 8667,
            "upload_time": "2023-01-29T15:28:31",
            "upload_time_iso_8601": "2023-01-29T15:28:31.176556Z",
            "url": "https://files.pythonhosted.org/packages/35/c7/db5b4b06f0115483d05fa91aa23259a3ce880865e1f1203ce5a8b2f43fa0/pytest-image-diff-0.0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-29 15:28:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "Apkawa",
    "github_project": "pytest-image-diff",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-image-diff"
}
        
Elapsed time: 0.24165s