Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when comparing images #7140

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

from PIL import Image, ImageMath, features

# overridden in conftest.py
pytestconfig = {"option": {"verbose": 0}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously discussed in #6653 (comment)
Screenshot 2023-05-08 at 7 30 46 am


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -87,15 +90,23 @@ def assert_image(im, mode, size, msg=None):
def assert_image_equal(a, b, msg=None):
assert a.mode == b.mode, msg or f"got mode {repr(a.mode)}, expected {repr(b.mode)}"
assert a.size == b.size, msg or f"got size {repr(a.size)}, expected {repr(b.size)}"
if a.tobytes() != b.tobytes():

original_verbosity = pytestconfig.option.verbose
try:
# set pytest's verbosity to 0 so that it doesn't show the full bytes diff
pytestconfig.option.verbose = 0
assert a.tobytes() == b.tobytes(), msg or "got different content"
except AssertionError:
if HAS_UPLOADER:
try:
url = test_image_results.upload(a, b)
logger.error(f"Url for test images: {url}")
except Exception:
pass

assert False, msg or "got different content"
raise
finally:
pytestconfig.option.verbose = original_verbosity


def assert_image_equal_tofile(a, filename, msg=None, mode=None):
Expand Down
11 changes: 11 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
pytest_plugins = ["Tests.helper"]


def pytest_configure(config):
"""
Keep a reference to pytest's configuration in our helper class.
This function is called by pytest each time the configuration is updated.
https://docs.pytest.org/en/latest/reference/reference.html#pytest.hookspec.pytest_configure
"""
import Tests.helper

Tests.helper.pytestconfig = config