Skip to content

Commit

Permalink
set verbosity to 0 before comparing image bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed May 7, 2023
1 parent 50f410c commit 56680b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 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}}

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -88,7 +91,10 @@ 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)}"

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:
Expand All @@ -99,6 +105,8 @@ def assert_image_equal(a, b, msg=None):
pass

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

0 comments on commit 56680b2

Please sign in to comment.